4 ms·
The second code example ("if you were doing this before ARC") is completely wrong. "alloc" is a class method that allocates memory for an instance, on which "in
by Camillo 11y ago
The second code example ("if you were doing this before ARC") is completely wrong. "alloc" is a class method that allocates memory for an instance, on which "init" is then called. Calling it on an instance returned by a factory method is nonsensical.
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.
- thealistra 11y agoThe 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).
- interpol_p 11y agoYeah, it looks like he meant to use `retain` rather than `alloc` (assuming he means to use them outside of the next autorelease pool drain).
- martind81 11y agoI stopped reading the article there. :)
- holyjaw 11y agoThe 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.
- AshFurrow 11y agoHa, yeah. Just a typo – it's been so long since I've had to write retain/release, and thank goodness!