我创造了一个课程:
@interface KVOGame : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *releaseDate;
@property (nonatomic, strong) KVOPlatform *platform;
@end还有另一个用来买它的:
@interface KVOPlatform : NSObject
@property (nonatomic, strong) NSString *platformName;
@property (nonatomic, strong) NSString *platformVersion;
@end然后我试着用KVC来获得像这样的"platformVersion“
@interface KVOViewController ()
@end
@implementation KVOViewController
- (void)viewDidLoad
{
[super viewDidLoad];
KVOGame *game = [[KVOGame alloc] init];
game.name = @"Bayonetta";
game.releaseDate = @"8.10.2009";
game.platform.platformName = @"PS3, Xbox360";
game.platform.platformVersion = @"all versions";
NSString *identifier = @"platform.platformVersion";
NSLog(@"%@", [game valueForKey:identifier]);
}它因错误而崩溃:
终止应用程序的原因是:“valueForUndefinedKey:这个类不符合键platform.platformVersion的键值编码。”
我做错了什么?
更新:valueForKeyPath:而不是valueForKey也不起作用。
发布于 2014-05-10 03:49:30
试试NSLog(@"%@", [game valueForKeyPath:identifier]);
我认为game.platform永远不会被创建。是零
https://stackoverflow.com/questions/23576871
复制相似问题