Objective c 如何将CAShapeLayer添加到NSDictionary
尝试将CAShaperLayer添加到NSDictionary时出现以下错误:Objective c 如何将CAShapeLayer添加到NSDictionary,objective-c,Objective C,尝试将CAShaperLayer添加到NSDictionary时出现以下错误: [<__NSDictionaryI 0x7fafe4826d70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key layer. 我试图搜索[NSValue valueWith…],但没有针对CAShapeLayer的方法 那么,如何将CAShapeLayer添加到NSDiction
[<__NSDictionaryI 0x7fafe4826d70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key layer.
我试图搜索[NSValue valueWith…],但没有针对CAShapeLayer的方法
那么,如何将CAShapeLayer添加到NSDictionary中呢?CashapperLayer是一个对象,在dict中没有任何问题。 你的问题是:你可以使用一个不可变的dict,在这种情况下,在你创建它的时候放进去:
NSDictionary *pixelDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:pixelLayer,@"layer", nil];
或者使用可变的dict:
NSMutableDictionary *pixelMutableDict = [[NSMutableDictionary alloc] init];
[pixelDictionary setValue:pixelLayer forKey:@"layer"];
NSMutableDictionary *pixelMutableDict = [[NSMutableDictionary alloc] init];
[pixelDictionary setValue:pixelLayer forKey:@"layer"];