Objective-C 编码规范


Objective-C Monday, April 22, 13 Spacing And Formatting • tab • 80 • @public and @private • @try, @catch, @finally ( Exception) Monday, April 22, 13 Spacing And Formatting • tab • 80 • @public and @private • @try, @catch, @finally ( Exception) Objective-C Google 50% 120 Monday, April 22, 13 - (void)doSomethingWithString:(NSString *)theString { ... } Monday, April 22, 13 - (void)doSomethingWith:(GTMFoo *)theFoo rect:(NSRect)theRect interval:(float)theInterval { ... } Monday, April 22, 13 - (void)short:(GTMFoo *)theFoo longKeyword:(NSRect)theRect evenLongerKeyword:(float)theInterval error:(NSError **)theError { ... } Monday, April 22, 13 [myObject doFooWith:arg1 name:arg2 error:arg3]; [myObject doFooWith:arg1 name:arg2 error:arg3]; [myObj short:arg1 longKeyword:arg2 evenLongerKeyword:arg3 error:arg4]; Monday, April 22, 13 Protocols @interface MyProtocoledClass : NSObject { @private id _delegate; } - (void)setDelegate:(id)aDelegate; @end Monday, April 22, 13 Blocks [operation setCompletionBlock:^{ [self onOperationDone]; }]; [operation setCompletionBlock:^{ [self.delegate newDataAvailable]; }]; Monday, April 22, 13 Blocks [[SessionService sharedService] loadWindowWithCompletionBlock:^(SessionWindow *window) { if (window) { [self windowDidLoad:window]; } else { [self errorLoadingWindow]; } }]; Monday, April 22, 13 Blocks [[SessionService sharedService] loadWindowWithCompletionBlock:^(SessionWindow *window) { if (window) { [self windowDidLoad:window]; } else { [self errorLoadingWindow]; } }]; Monday, April 22, 13 Blocks [[SessionService sharedService] loadWindowWithCompletionBlock:^(SessionWindow *window) { if (window) { [self windowDidLoad:window]; } else { [self errorLoadingWindow]; } }]; Monday, April 22, 13 File Names .h C/C++/Objective-C header file .m Objective-C implementation file .mm Objective-C++ implementation file .c Pure C++ implementation file .cc C implementation file File names for categories should include the name of the class being extended. eg: GTMNSTextView+Autocomplete.h Monday, April 22, 13 Class Names • • • TCCommon Monday, April 22, 13 Category Names • // Extending a framework class: @interface NSString (TCStringParsingAdditions) - (NSString *)md5; @end Monday, April 22, 13 Objective-C Method Name • • • • replaceCharactersInRange:withString: Monday, April 22, 13 • • • • • k • (#defines, enums, const local variables, etc.) Monday, April 22, 13 Declaration Comments • interface, category, protocol • • Monday, April 22, 13 Cocoa and Objective-C Features • • • NSObject @implemention ( init..., dealloc) • 0 nil Monday, April 22, 13 Cocoa and Objective-C Features • new • public public public • #include C C++ Monday, April 22, 13 Cocoa and Objective-C Features Include root frameworks over individual files. Monday, April 22, 13 Cocoa and Objective-C Features • alloc object autorelease release release release return • autorealse then retain: Monday, April 22, 13 Cocoa and Objective-C Features • init dealloc Monday, April 22, 13 Cocoa and Objective-C Features • BOOL BOOL YES(1) NO(0) BOOl • YES Monday, April 22, 13 Cocoa and Objective-C Features • @property nonatomic • . @property array.count Monday, April 22, 13 Cocoa Patterns • Delegate objects should not be retained • Model, View, Controller @protocols MVC Monday, April 22, 13 Xcode 120 Monday, April 22, 13 Xcode tab Monday, April 22, 13 Thank you ! Monday, April 22, 13
还剩28页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 8 金币 [ 分享pdf获得金币 ] 1 人已下载

下载pdf

pdf贡献者

631348609

贡献于2013-10-10

下载需要 8 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf