Xcode常见警告汇总(持续更新)
Posted JoySeeDog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xcode常见警告汇总(持续更新)相关的知识,希望对你有一定的参考价值。
Update to recommended settings
原因: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]
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++)
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-initializers-using-ns-designated-initializer
Bitmasking for introspection of Objective-C object pointers is strongly discouraged
苹果不推荐用于内省Objective-C对象指针的位掩码运算
解决方法:某数字& 0x1的时候是代表要取最低位是否为1,把(JK_EXPECT_F(((NSUInteger)object) & 0x1))
改成了 (JK_EXPECT_F(((NSUInteger)object)%2))
即可。
5enumeration values not handled in switch: ‘…
枚举里面的所有类型在switch里面并没有全部的对应起来。如果并不是都需要使用,最好是把所有的情况都补全。如果确实不需要所有功能,也应该在下面default break里面补全并打印LOG.
typedef NS_ENUM(NSInteger,AnimalName)
Dog,
Cow,
Hen,
Cat,
Pig
;
下面的情况会出现警告
AnimalName animalName = Pig;
switch (animalName)
case Dog:
break;
case Hen:
break;
添加Default警告消失
AnimalName animalName = Pig;
switch (animalName)
case Dog:
break;
case Hen:
break;
default:
NSLog(@"animalName is %ld",animalName);
break;
Assigning to ‘id _Nullable’ from incompatible type ‘OLLiveGiftView *const __strong’
在10.0的API中,CAAnimationDelegate变成了协议。而在iOS10以前则是以分类的形式。
iOS 9.3的代码
@property(nullable, strong) id delegate;
/* When true, the animation is removed from the render tree once its
* active duration has passed. Defaults to YES. */
@property(getter=isRemovedOnCompletion) BOOL removedOnCompletion;
@end
/* Delegate methods for CAAnimation. */
@interface NSObject (CAAnimationDelegate)
/* Called when the animation begins its active duration. */
- (void)animationDidStart:(CAAnimation *)anim;
/* Called when the animation either completes its active duration or
* is removed from the object it is attached to (i.e. the layer). 'flag'
* is true if the animation reached the end of its active duration
* without being removed. */
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@end
iOS10.0的代码
@property(nullable, strong) id <CAAnimationDelegate> delegate;
/* When true, the animation is removed from the render tree once its
* active duration has passed. Defaults to YES. */
@property(getter=isRemovedOnCompletion) BOOL removedOnCompletion;
@end
/* Delegate methods for CAAnimation. */
@protocol CAAnimationDelegate <NSObject>
@optional
/* Called when the animation begins its active duration. */
- (void)animationDidStart:(CAAnimation *)anim;
/* Called when the animation either completes its active duration or
* is removed from the object it is attached to (i.e. the layer). 'flag'
* is true if the animation reached the end of its active duration
* without being removed. */
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@end
修改方法就是在类的实现里面添加协议就好。
@implementation ViewController<CAAnimationDelegate>
is deprecated: first deprecated in XXX
解决方法:方法过期使用新方法
Values of type ‘NSInteger’ should not be used as format arguments; add an explicit cast to ‘long’ instead
解决办法
[NSString stringWithFormat:@“%ld", (long)number];
接入第三方SDK异常
接入新浪微博,微信等异常,Error OSStatus -10814 ,Error 308
-canOpenURL: failed for URL: "weixin://app/wx368afdba2d19c1fa/" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.010672 MYDemo[1747:940399] -canOpenURL: failed for URL: "wtloginmqq2://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.011959 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqopensdkapiV3://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.013144 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqwpa://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.014703 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqopensdkapiV2://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.015940 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqOpensdkSSoLogin://qqapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.017359 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqq://qqapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.018724 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqzoneopensdkapiV2://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.020263 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqzoneopensdkapi19://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.021645 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqzoneopensdkapi://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.023895 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqzoneopensdk://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.025568 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqzone://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.026643 MYDemo[1747:940399] -canOpenURL: failed for URL: "wtloginmqq2://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.027799 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqopensdkapiV3://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.029189 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqwpa://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.032464 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqopensdkapiV2://qzapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.034013 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqqOpensdkSSoLogin://qqapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.035385 MYDemo[1747:940399] -canOpenURL: failed for URL: "mqq://qqapp" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.067138 MYDemo[1747:940399] -canOpenURL: failed for URL: "sinaweibo://" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
2016-11-22 14:54:24.068271 MYDemo[1747:940399] -canOpenURL: failed for URL: "sinaweibohd://" - error: "未能完成操作。(“OSStatus”错误 -10814。)"
可以到
https://www.osstatus.com/search/results?platform=all&framework=all&search=-10814%23 查询对应的原因
解决方法:http://stackoverflow.com/questions/38689631/how-to-use-facebook-ios-sdk-on-ios-10
以上是关于Xcode常见警告汇总(持续更新)的主要内容,如果未能解决你的问题,请参考以下文章