自己曾经没注意的东西

一些曾经自己没注意到的

1.error handling  :: When methods return an error parameter by reference, check the returned value, not the error variable

NSError *error = nil;

if(![self trySomethingWithError:&error]){

}

2. 命名:

constans :: Constants should be camel-case with all words capitalized and prefixed by the related class name for clarity.

   static const NSTimeInterval ZOCSignInViewControllerFadeOutAnimationDuration = 0.4;

::Constants exposed externally should use this pattern in the interface file:

extern NSString *const ZOCCacheControllerDidClearCacheNotification;

Method:: The usage of the word "and" is reserved. It should not be used for multiple parameters as illustrated
in the initWithWidth:height: example below.

literals:: 用最简便的方法初始化,防止没有对象生产,如NSArray


回顾单例写法
+ (instancetype)sharedInstance{
  static id shareInstance = nil;
  static dispatch_once_t onceToken = 0;
  
  dispatch_once(&onceToken,^{
    sharedInstance = [[self alloc] init];
  });
  return sharedInstance;  
}



block::
__weak __typeof(self) weakSelf = self;
[self executeBlock:^(NSData *data, NSError *error) {
    [weakSelf doSomethingWithData:data];
}];

__weak __typeof(self)weakSelf = self;
[self executeBlock:^(NSData *data, NSError *error) {
    __strong __typeof(weakSelf) strongSelf = weakSelf;
    if (strongSelf) {
        [strongSelf doSomethingWithData:data];
        [strongSelf doSomethingWithData:data];
    }
}];
 




posted @ 2015-04-11 10:37  OHeroJ  阅读(149)  评论(0编辑  收藏  举报