The author is Ash Furrow, who has written numerous Obj-C books and apps. I highly doubt he's confused about Obj-C; he'll probably turn up in this thread at some point though, so it may be worth asking.
Re:Emerging Best Practices in Swift
by AshFurrow on Wednesday November 18, 2015 @04:15PM
(#10590798)
Ha, yeah. Just a typo – it's been so long since I've had to write retain/release, and thank goodness!
Re:Emerging Best Practices in Swift
by interpol_p on Tuesday November 17, 2015 @10:48PM
(#10585791)
Yeah, it looks like he meant to use `retain` rather than `alloc` (assuming he means to use them outside of the next autorelease pool drain).
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.
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.
* 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).
The error is made consistently all three times, so it's clear that the author is genuinely confused about Objective-C. Maybe he's better at Swift, but it doesn't look good.