Xcode常见警告汇总(持续更新)

本文汇总了Xcode中常见的警告,包括Update to recommended settings、Precompiled header uses DATE or TIME、不同符号整数比较等,并提供了详细的解决方法,帮助开发者优化代码。
摘要由CSDN通过智能技术生成

原因:Xcode所支持的iOS版本大于工程设置的版本。
点击警告,弹出如下提示,为所有项目升级Target和Project升级版本。

这里写图片描述

或是直接在在此处逐一进行修改
这里写图片描述

Precompiled header uses DATE or TIME

解决方法:
https://github.com/ibireme/YYKit/issues/152

warning: multi-character character constant [-Wfour-char-constants]

解决方法:
http://stackoverflow.com/questions/7459939/what-do-single-quotes-do-in-c-when-used-on-multiple-characters

Comparison of integers of different signs: ‘int’ and ‘NSUInteger’ (aka ‘unsigned long’)

使用数组的,count属性的时候容易出这个问题。
for (int j = 0 ; j < [emotions count]; j++) {

}
由于数组索引不可能为负数,所以count是一个无符号整形,j是一个有符号整形。类型没有同意所以出现异常,同时, NSInteger在64位上是long 在32位上是int所以还是使用long比较保险,不会出现溢出情况。

 for (unsigned long  j = 0 ; j < [emotions count]; j++) {
 }

参考地址:
http://stackoverflow.com/questions/8350971/comparison-of-integers-of-different-signs-warning-with-xcode

Implementing deprecated method

使用了Object-C垃圾回收器不支持的方法 Objective-C garbage collection is no longer supported.

Method override for the designated initializer of the superclass ‘-init’ not found

reason:

  • The designated initializer guarantees the object is fully initialised by sending an initialization message to the superclass. The implementation detail becomes important to a user of the class when they subclass it. The rules for designated initializers in detail:

  • A designated initializer must call (via super) a designated initializer of the superclass. Where NSObject is the superclass this is just [super init].

  • Any convenience initializer must call another initializer in the class - which eventually leads to a designated initializer.

  • A class with designated initializers must implement all of the designated initializers of the superclass.

解决方法:

example:

@interface MyClass : NSObject
@property(copy, nonatomic) NSString *name;
-(instancetype)initWithName:(NSString *)name NS_DESIGNATED_INITIALIZER;
-(instancetype)init;
@end
/**
then the compiler checks if the (convenience) initializer init calls the (designated) initializer initWithName:, so this would cause a warning:
*/
-(instancetype)init
{
    self = [super init];
    return self;
}
//and this would be OK:

-(instancetype)init
{
    self = [self initWithName:@""];
    return self;
}

http://stackoverflow.com/questions/32741123/objective-c-warning-method-override-for-the-designated-initializer-of-the-superc
http://stackoverflow.com/questions/26185239/ios-designated-ini

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值