News for hackers. Stuff that matters.
Re:Emerging Best Practices in Swift by thealistra on Tuesday November 17, 2015 @06:55PM (#10584904)
The code samples were weird. Why injected property has to be optional, we can inject it using the constructor.
Re:Emerging Best Practices in Swift by Glide on Tuesday November 17, 2015 @11:00PM (#10585831)
I 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.
Re:Emerging Best Practices in Swift by AshFurrow on Wednesday November 18, 2015 @04:17PM (#10590819)
Yup.
Re:Emerging Best Practices in Swift by archagon on Tuesday November 17, 2015 @11:36PM (#10585943)
* 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).