r/iOSProgramming • u/halpz • Oct 22 '15
Library A UIButton subclass I made that allows you to set its action in a block
https://github.com/halpz/PHBlockButton2
u/paulryanclark Oct 23 '15 edited Oct 23 '15
Few quick thoughts:
Your Action typedef name is too generic, you may conflict with someone using your library. Always good to prefix your library typedefs such as PHButtonActionBlock. Having "block" in the typedef also helps to convey that you are expecting a block.
As well, look into class clusters to understand if your implementation conflicts with UIButton's class cluster.
"Init" prefixed methods should be reserved, and are not normally class methods. Use "+buttonWithAction:" to be more inline with what people expect from a class factory method.
PHBlockButton *button = [super buttonWithType:UIButtonTypeCustom];
Should be: PHBlockButton *button = [self buttonWithType:UIButtonTypeCustom];
If you leave super, then you prevent subclasses from overriding "buttonWithType" to suit their needs
0
Oct 22 '15
[deleted]
1
u/supercodes Oct 23 '15
I didn't downvote, but I didn't upvote either. The whole thing is very simple, why would anyone need to use this instead of implementing it themselves?
I'm sure this is useful for you, but I just don't see anyone seeking this out and using it, and actually saving time doing so.
But that's just like, you know, my opinion, man.
1
u/halpz Oct 23 '15
sure, but I just thought something like this would be useful for beginners; I struggled to understand the use of blocks etc until I saw it implemented simply like this.
2
u/th3phantom Oct 22 '15
great code dude.