4 ms·
The code samples were weird. Why injected property has to be optional, we can inject it using the constructor.
by thealistra 11y ago
The code samples were weird. Why injected property has to be optional, we can inject it using the constructor.
- Glide 11y agoI think the DI was for a view controller in this case. In normal usage I would agree. DI -> use the constructor. Even in languages like Java and C# I would advocate constructor injection. View controllers and where they get instantiated with storyboards, xibs, etc? Not so much.
- AshFurrow 11y agoYup.
- archagon 11y ago* Lazy init for non-unit-test use. * No need to have 20 parameters in your init method signature. * Imitates Cocoa standard practices re: delegates. * Swift's optional binding makes it safe if you don't force-unwrap objects (and makes your code more robust to boot).