News for hackers. Stuff that matters.
Re:Emerging Best Practices in Swift by Camillo on Tuesday November 17, 2015 @05:02PM (#10584314)
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.

Re:Emerging Best Practices in Swift by holyjaw on Wednesday November 18, 2015 @12:46AM (#10586167)
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.
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).

Re:Emerging Best Practices in Swift by martind81 on Tuesday November 17, 2015 @11:35PM (#10585939)
I stopped reading the article there. :)