Written by
Amy
on
on
Keep Learning
objc.io review note
I’m subscribing objc.io online contents on monthly plan. It is an platform which provides In-depth guides on iOS and macOS development. This post is for keeping track of the Swift coding concepts that I encountered through objc.io.
Delegates & Callbacks
✳︎ Swift Talk #24 Delegates & Callbacks
↳ NOTE
- Another advantage of delegate protocols is that you can group multiple methods that belong together. Furthermore, it’s relatively easy to implement an API where you can register and unregister multiple delegates. This is much more difficult with callback functions, e.g. you’d need to return a token when registering a callback, which you can use later on to unregister this specific callback.
Sharing State between VCs
↳ NOTE
- Tip. Embedding ViewControllers through Container
- Opinion. It seems container view’s viewDidLoad is called earlier than owner.
Collection protocol
✳︎ Swift Talk #32 Array, ArraySlice & Collection
↳ NOTE
- For me, Collection protocol is an amazing & interesting topic. :)
extension Collection {
func split(batchSize: IndexDistance) -> [SubSequence] {
var remainderIndex = startIndex
var result: [SubSequence] = []
while remainderIndex < endIndex {
let batchEndIndex = index(remainderIndex, offsetBy: batchSize, limitedBy: endIndex) ?? endIndex
result.append(self[remainderIndex..<batchEndIndex])
remainderIndex = batchEndIndex
}
return result
}
}
Auto Layout with Key Paths
✳︎ Swift Talk #75 Auto Layout with Key Paths
=== : ==
- === is really asking: “Do both these variables hold the same reference as their value?”
- Programming language literature, == is sometimes called structural equality, and === is called pointer equality or reference equality.
Reference
- A variable that holds a reference can be declared with let — that is, the reference is constant. This means that the variable can never be changed to refer to something else.
- But it doesn’t mean that the object it refers to can’t be changed. — **it’s only constant in what it points to. It doesn’t mean what it points to is constant. **
Polymorphic features
- Subtyping and method overriding is one way of getting polymorphic behavior, - generics, where a function or method is written once to take any type that provides certain functions or methods, but the implementations of those functions can vary.
- Unlike method overriding, the results of function overloading and generics are known statically at compile time.