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方法不拥有。您必须仍然使用一个合适的类型转换,html

1down voteaccepted编程

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

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:ide

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-tyui

相关文章
相关标签/搜索