Perpetio iOS Compilation #1
There is nothing better than constant learning and grow. Our iOS team knows that for sure, as we practice different activities dedicated to knowledge sharing. And now is the time to share it within the tech community! Check out the resources below and do not hesitate to reach us with any comments!
Articles:
- Great explanation of Opaque Return Types added in Swift 5.1 that is a big part of the new SwiftUI framework's functionality
https://swiftrocks.com/understanding-opaque-return-types-in-swift.html - And another one reading with good examples about Property Wrappers from Swift 5.1 https://medium.com/ios-expert-series-or-interview-series/property-wrappers-part-i-e18cd71b55ae
- If you encountered with the impossibility of creating an array of generic objects with different associated types, please read a great research about covariance and contravariance in Swift. In this article you will also find out which types are covariant and which are invariant in its implementation https://medium.com/@aunnnn/covariance-and-contravariance-in-swift-32f3be8610b9
- Swift 5.1 version introduced the keyword `some` (used for opaque types), which easily resolves the Self or associated type requirements, but this keyword is only available from iOS 13. If you would like to resolve this in an earlier version, please read this brief article about Type Erasure pattern that works with Swifthttps://medium.com/@chris_dus/type-erasure-in-swift-84480c807534
- It is easy to forget but Auto Layout does not use the view frame when positioning views. It uses the view alignment rectangle. Most of the time you do not need to worry about alignment rectangles as they match the view frame. It gets more interesting when you have a view that includes a drop shadow or glow effect or some other non-content addition such as a badge which can throw the default alignment off. This post looks at how to define custom alignment rectangles to tell Auto Layout how to align such views.
https://useyourloaf.com/blog/auto-layout-and-alignment-rectangles/
Controls/Utils
- Repo description says "Composing NSAttributedString with SwiftUI-style syntax" - it's exactly what you need if you want to have SwiftUI-code-style for all your project source code.
https://github.com/ethanhuang13/NSAttributedStringBuilder
Example:
let attributedString = NSAttributedString {
AText("Hello world")
.font(.systemFont(ofSize: 24))
.foregroundColor(.red)
LineBreak()
AText("with Swift")
.font(.systemFont(ofSize: 20))
.foregroundColor(.orange)
}
- Jesse Squires tried to replace CocoaPods with Swift Package Manager in a couple of his small projects and shared his feedback of that experiment. https://www.jessesquires.com/blog/replacing-cocoapods-with-swiftpm/
Got interested? Just describe your idea and we will get back to you! contact@perpet.io