iOS--消除警告与定制警告

一:消除警告
警告1.没有用到

#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wunused-variable"

    // unused-variable 类型的警告代码!

#pragma clang diagnostic pop

警告2.方法弃用

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:message message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];
    [alert performSelector:@selector(dismissWithClickedButtonIndex:animated:) withObject:nil afterDelay:2];

#pragma clang diagnostic pop

注解:

#pragma clang diagnostic push

#pragma clang diagnostic ignored “字段详见:警告类型”

//警告类型对应的警告代码块

#pragma clang diagnostic pop

|___________________________________________________
二:自己写警告

警告1:方法在这个范围内使用:NS_DEPRCATED_IOS(范围)

/**验证手机号码是否正确*/
+ (void)checkPhoneNumber:(NSString *)phoneNumString completed:(completed) completed NS_DEPRECATED_IOS(2_0, 4_0);

警告2:自定义警告提示信息:__attribute((deprecated(“邮箱的正则表达式需要精简”)))

+ (void)checkEmail:(NSString *)emailString completed:(completed)completed __attribute((deprecated("邮箱的正则表达式需要精简")));

你可能感兴趣的:(iOS--技术知识)