"Pushing Protocols to Their Limits"
summary
App code groups transactions into per-day sections using either a Swift array or Realm Results and defines a DateGroupedCollection protocol with an associatedtype Element: DateGroupable. Attempts to store that protocol directly fail, making the feed view controller generic (breaking Interface Builder and @objc extensions) or trying opaque types (some View) which cannot be a stored property. The final solution builds a type erasure wrapper AnyDateGroupedCollection that forwards via closures to DateGroupedArray or DateGroupResults so the controller uses a concrete type.
AI-written summary · about
chapters (26)
- 0:00Introduction
- 0:30Context
- 1:25Grouping
- 2:44Protocols
- 3:56associated types
- 4:25standard library examples
- 6:01dategroups collection
- 6:55feeditems
- 8:03Generics
- 8:30Issues with Generics
- 9:28What are Opaque Types
- 9:52Swift UI Example
- 10:23Opaque Types
- 11:37Date Groups Collection
- 11:50Can we infer a concrete return type
- 12:43What about Swift UI
- 14:16What is a type erase wrapper
- 14:50The standard library
- 15:08Any collection
- 15:53Supporting associated types
- 16:37Implementation
- 19:00Closure Properties
- 22:19Wrapping
- 23:12Rename
- 24:08Recap
- 25:04Summary
