Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



This 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!


Yeah, 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.


instancetype is implicit for init (and related methods): 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: