valueForKeyPathでエラー発生
公開日:
:
最終更新日:2014/02/04
未分類
記事内に広告を含む場合があります。記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。
#import <Foundation/Foundation.h>
@interface MyObject : NSObject
{
NSMutableArray* array;
float power;
}
@property (nonatomic, retain) NSMutableArray* array;
@property (nonatomic, assign) float power;
@end
@implementation MyObject
@synthesize array;
@synthesize power;
- (id) init
{
self = [super init];
if (self != nil) {
self.array = [NSMutableArray array];
}
return self;
}
- (void)dealloc {
[array release];
[super dealloc];
}
@end
int main() {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
MyObject* object1 = [[[MyObject alloc] init] autorelease];
object1.power = 1.1f;
MyObject* object2 = [[[MyObject alloc] init] autorelease];
object2.power = 2.2f;
MyObject* object3 = [[[MyObject alloc] init] autorelease];
object3.power = 3.3f;
MyObject* object4 = [[[MyObject alloc] init] autorelease];
object4.power = 4.4f;
MyObject* object5 = [[[MyObject alloc] init] autorelease];
[object5.array addObject:object1];
[object5.array addObject:object2];
MyObject* object6 = [[[MyObject alloc] init] autorelease];
[object6.array addObject:object3];
[object6.array addObject:object4];
MyObject* object7 = [[[MyObject alloc] init] autorelease];
[object7.array addObject:object5];
[object7.array addObject:object6];
NSLog(@"%@", [object7 valueForKeyPath:@"array"]);
NSLog(@"%@", [object7 valueForKeyPath:@"array.array"]);
NSLog(@"%@", [object7 valueForKeyPath:@"array.array.power"]);
NSLog(@"%@", [object7 valueForKeyPath:@"@max.array.array.power"]); // error
NSLog(@"%@", [object7 valueForKeyPath:@"array.@max.array.power"]); // error
NSLog(@"%@", [object7 valueForKeyPath:@"array.array.@max.power"]); // error
[pool release];
return 0;
}
実行時に以下のようなエラーが出てしまう。うーん、こういう集計はできないのかなあ・・・。
2009-06-02 01:31:51.045 valueForKeyPath2[91393:10b] *** -[NSCFArray compare:]: unrecognized selector sent to instance 0x113f10
2009-06-02 01:31:51.045 valueForKeyPath2[91393:10b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[NSCFArray compare:]: unrecognized selector sent to instance 0x113f10’
関連記事
- PREV
- 操舵行動
- NEXT
- モバイルデジタルサイネージレザーバッグ with iPhoneケース