我正在阅读 Parse 的 iOS 开发人员指南。
我对它显示 PFObject
使用下标语法分配给键感到困惑。
PFObject *gameScore = [PFObject objectWithClassName:@"GameScore"];
gameScore[@"score"] = @1337;
gameScore[@"playerName"] = @"Sean Plott";
gameScore[@"cheatMode"] = @NO;
PFObject *gameScore = [PFObject objectWithClassName:@"GameScore"];
gameScore[@"score"] = @1337;
首先我认为 PFObject
一定是扩展了 NSMutableDictionary
,但是 PFObject
只是扩展了 NSObject
。它如何表现得像 NSMutableDictionary
?
我如何为我自己的类(class)做这件事?
最佳答案
NSHipster有答案:
Similarly, custom-keyed subscripting can be added to your class by declaring and implementing these methods:
- (id)objectForKeyedSubscript:(*KeyType*)key;
- (void)setObject:(id)obj forKeyedSubscript:(*KeyType*)key;
关于objective-c - PFObject 如何允许像 NSMutableDictionary 这样的下标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32680739/