码迷,mamicode.com
首页 > 其他好文 > 详细

自己曾经没注意的东西

时间:2015-04-11 11:38:12      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

一些曾经自己没注意到的

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];
    }
}];
 




自己曾经没注意的东西

标签:

原文地址:http://www.cnblogs.com/Ohero/p/4417141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!