4 ms·
Looks cool, but it felt a bit short or am I missing something? Sorry for being this person... Your init selector should return 'instancetype' and not 'id' if
by seivan 13y ago
Looks cool, but it felt a bit short or am I missing something?
Sorry for being this person...
Your init selector should return 'instancetype' and not 'id' if it is an instance of the class you're returning (which init should!)
Not much of a benefit here, but it's a good habit to get into.
The benefit comes once you do protocols for multiple classes that could return an instance of the class.
@protocol SHReversing <NSObject>
-(instancetype)SH_reversedObject;
@end
@interface NSArray (SHReversing)
<SHReversing>
@end
@interface NSOrderedSet (SHReversing)
<SHReversing>
@end
- DesaiAshu 13y agoThis tutorial will eventually serve as the intro into our full tutorials (which unfortunately still require you to download Xcode :), but it's going to be really useful for us to reduce friction for devs getting started. Also this was our submission for CSEdWeek's Hour of Code next week, we're pretty excited to get more kids exposed to programming!
- bennyg 13y agoYeah, there's some weird stylistic choices with it, but overall pretty cool. I'm compiling to see if some interesting things I've done actually work or not.
- gurkendoktor 13y agoinstancetype is implicit for init (and related methods): http://stackoverflow.com/a/14652187 http://stackoverflow.com/a/14652187 The clang link seems to confirm that it doesn't even make a difference to throw @protocols into the mix, it only seems to consider the method name.