关于 Pragma 的使用总结

  注意:此文乃是本人阅读多个博客文章后,记下的个人认为重点的地方。

  参考文章:

    参考1   参考2

 

 

  • #Pragma mark - 用于分离类中的不同功能的方法。(例如,一个 viewController 一般需要这样划分)
#pragma mark - life cycle
- (void)dealloc {
    // [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

#pragma mark - UIXXXXDelegate

#pragma mark - CustomDelegate

#pragma mark - event response

#pragma mark - private methods

#pragma mark - getters and setters

  

  • 全局忽略 performSelect
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

  

  • 局部忽略 performSelect
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

[myObj performSelector:mySelector withObject:name];

#pragma clang diagnostic pop

  

  • 设置忽略不使用变量的警告 #pragma unused
- (void)giveMeFive
{
    NSString *foo;
    #pragma unused (foo)

    return 5;
}

  

  • 明确编译错误或者警告 (#error, #Warning 用于提醒别人或者自己代码尚有缺陷的时候很管用)
- (NSInteger)divide:(NSInteger)dividend by:(NSInteger)divisor
{
    #error Whoa, buddy, you need to check for zero here!
    return (dividend / divisor);
}

  

- (float)divide:(float)dividend by:(float)divisor
{
    #warning Dude, don't compare floating point numbers like this!
    if (divisor != 0.0) {
        return (dividend / divisor);
    }
    else {
        return NAN;
    }
}

 

  • 设置忽略 Depracated Method 的警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    // call deprecated method without warning
    
#pragma clang diagnostic pop

  

  

 

posted on 2015-08-05 09:14  EileenLeung  阅读(614)  评论(0编辑  收藏  举报