Cocoa is a dynamically typed language, and you can easily get confused on what the type you were working with.
Collections (arrays, dictionaries, and so on) don ' t has types associated with them, so it's very easy to code
Something accidentally like this:
Nsarray *dates = @[@ "1/1/2000"];
NSDate *firstdate = [dates firstobject];
This code compiles without a warning, but would crash with an unknown
Selector exception.
Let's look at following code lines:
-(void) SetUrl: (NSString *) URL; Bad
-(void) seturlstring: (NSString *) string; Good
-(void) SetUrl: (Nsurl *) URL; Good
Category methods
Because of the possibility of collisions, you should add a prefix to your category methods
Cocoa generally doesn ' t use embedded underscores
A good use of categories are to provide utility methods to existing classes. When did this, I recommend
Naming the header and implementation files using the name of the original class plus the name of the
Extension.
For example, you might create a simple ptlextensions category on NSDate:
Nsdate+ptlextensions.h
@interface nsdate (ptlextensions)- (Nstimeinterval) Ptl_timeintervaluntilnow; @end
Nsdate+ptlextensions.m
@implementation nsdate (ptlextensions)- (nstimeinterval) ptl_timeintervaluntilnow { return -[ Self timeintervalsincenow];} @end