collection element of type 'CGColorRef _Nullable' (aka'stuct CGColor*')is not an Objective-C object

类型转换为ID解决问题: “Collection element of type 'CGColorRef' (aka 'struct CGColor *') is not an Objective-C object”

编译器理解Objective-C方法返回的核心基础类型遵循历史可命名约定(见-高级内存管理编程指南)。例如,编译器知道,在iOS的cgcolor返回用UIColor的cgcolor方法不拥有。您必须仍然使用一个合适的类型转换,

1down voteaccepted

It is documented in the "Transitioning to ARC Release Notes":

The compiler understands Objective-C methods that return Core Foundation types follow the historical Cocoa naming conventions (see Advanced Memory Management Programming Guide). For example, the compiler knows that, in iOS, the CGColor returned by the CGColor method of UIColor is not owned. You must still use an appropriate type cast, as illustrated by this example:

NSMutableArray *colors = [NSMutableArray arrayWithObject:(id)[[UIColor darkGrayColor] CGColor]];
[colors addObject:(id)[[UIColor lightGrayColor] CGColor]];

 

参考:http://stackoverflow.com/questions/21933209/why-type-cast-to-id-will-get-rid-of-this-error-message-collection-element-of-ty

转载于:https://my.oschina.net/u/2345393/blog/760236

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值