标签:导致 xcode 事件 nsstring 函数返回 float ges geo mutable
作为一名合格的编码人员, 特别是打算以后长时间从事IT这一行业的人来说, 应该要明确一点: 我们写的代码不只是写给自己看的, 优雅的编码风格以及良好的代码注释对我们日常的开发是十分有必要的. 当我们在编写代码时, 要有一个意识: 此刻有千千万万的人正在看着自己写代码, 如何让他们都能快速看懂自己写的代码, 这就需要我们在平常开发的时候, 时时刻刻都要进行代码规范.
// 正例: static NSStirng * const HomeViewControllerDidReceiveRefreshNotification = @”HomeViewControllerDidReceiveRefreshNotification”; // 反例: static NSString * const refresh = @”refresh”;
typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) { AFNetworkReachabilityStatusUnknown = -1, AFNetworkReachabilityStatusNotReachable = 0, AFNetworkReachabilityStatusReachableViaWWAN = 1, AFNetworkReachabilityStatusReachableViaWiFi = 2 };
NSApplicationDidBecomeActiveNotification
NSWindowDidMiniaturizeNotification
NSTextViewDidChangeSelectionNotification
NSColorPanelColorDidChangeNotification
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
NSHighlightRect
NSDeallocateObject
unsigned int NSEventMaskFromType(NSEventType type) float NSHeight(NSRect aRect)
const char *NSGetSizeAndAlignment(const char *typePtr, unsigned int *sizep, unsigned int *alignp)
BOOL NSDecimalIsNotANumber(const NSDecimal *decimal)
//清晰 insertObject:atIndex: //不清晰,insert的对象类型和at的位置属性没有说明 insert:at: //清晰 removeObjectAtIndex: //不清晰,remove的对象类型没有说明,参数的作用没有说明 remove:
//清晰 destinationSelection setBackgroundColor: //不清晰,不要使用简写 destSel setBkgdColor:
//动词打头的方法表示让对象执行一个动作 - (void)invokeWithTarget:(id)target; - (void)selectTabViewItem:(NSTabViewItem *)tabViewItem;
//正确,使用属性名来命名方法 - (NSSize)cellSize; //错误,添加了多余的动词前缀 - (NSSize)calcCellSize; - (NSSize)getCellSize;
//正确 - (void)setCanHide:(BOOL)flag; - (BOOL)canHide; - (void)setShouldCloseDocument:(BOOL)flag; - (BOOL)shouldCloseDocument; //错误,不要使用"do"或者"does" - (void)setDoesAcceptGlyphInfo:(BOOL)flag; - (BOOL)doesAcceptGlyphInfo;
#pragma mark - private methods - (void)samplePrivateMethod {...} - (void)sampleForIf {...}
- (void)sampleForWhile {...} - (void)sampleForSwitch {...} - (void)wrongExamples {...} #pragma mark - public methods - (void)samplePublicMethodWithParam:(NSString*)sampleParam {...} #pragma mark - life cycle methods - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {...} - (void)viewDidLoad {...}
#pragma mark - ?? 注册接口 ?? ?? /** * 注册接口 * * @param mobilePhone 注册手机号号 * @param areaId 手机区域号ID * @param code 验证码 * @param pwd 注册密码 */ - (NSURLSessionDataTask *)registerWithMobilePhone:(NSString *)mobilePhone areaId:(NSString *)areaId code:(NSString *)code pwd:(NSString *)pwd success:(SuccessBlock)success failure:(FailureBlock)failure;
//正确,直接访问实例变量 - (instancetype)init { self = [super init]; if (self) { _bar = [[NSMutableString alloc] init]; } return self; } - (void)dealloc { [_bar release]; [super dealloc]; } //错误,不要通过存取方法访问 - (instancetype)init { self = [super init]; if (self) { self.bar = [NSMutableString string]; } return self; } - (void)dealloc { self.bar = nil; [super dealloc]; }
- (void)setFoo:(NSString *)aFoo { _foo = [aFoo copy]; }
// 正例: CGRect frame = self.view.frame; CGFloat x = CGRectGetMinX(frame); CGFloat y = CGRectGetMinY(frame); CGFloat width = CGRectGetWidth(frame); CGFLoat height = CGRectGetHeight(frame); // 反例: CGRect frame = self.view.frame; CGFloat x = frame.origin.x; CGFloat y = frame.origin.y; CGFloat width = frame.size.width; CGFLoat height = frame.size.height;
// 正例: if (!user.UserName) return NO; if (!user.Password) return NO; if (!user.Email) return NO; return YES; // 反例: BOOL isValid = NO; if (user.UserName) { if (user.Password) { if (user.Email) isValid = YES; } } return isValid;
标签:导致 xcode 事件 nsstring 函数返回 float ges geo mutable
原文地址:http://www.cnblogs.com/fanxiaocong/p/6511340.html