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

相關文章
相關標籤/搜索