自定义init parse.com

时间:2013-01-11 06:06:36

标签: objective-c parsing init parse-platform

我正在用PFObject的子类(Parse.com)编写一些类。

实施例: LBSomeClass.h

@interface LBSomeClass : PFObject
@propertise (strong,nonatomic) NSString* prop1;
@propertise (strong,nonatomic) NSString* prop2;
-(id)init;
-(id)initWithId:(NSString*)uid;
@end

LBSomeClass.m

@implementation LBPhoto
@synthesize prop1;
@synthesize prop2;

-(id)init {
self = [super init];
return self;
}

-(id)initWithId:(NSString*)uid {
self = [super init];
PFQuery* query = [PFQuery queryWithClassName:@"someclass"];
self = (LBSomeClass*)[query getObjectWithId:uid];

self.prop1 = [self objectForKey:@"propertiseone"]; //error here
self.prop2 = [self objectForKey:@"propertisetwo"]; //error here

return self;
}

但是当我跑步时,出现了一些错误:

[PFObject setProp1:]: unrecognized selector sent to instance 0xa2707d0
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFObject setProp1:]: unrecognized selector sent to instance 0xa2707d0'
你帮我解决了吗?非常感谢!!!

问题解决了!!!

-(id)initWithId:(NSString*)uid {
self = [super initWithClassName:@"Photo"];
[self setObjectId:targetID];

[self fetch];

self.prop1 = [self objectForKey:@"propertiseone"];
// other
}

2 个答案:

答案 0 :(得分:0)

我解决的问题哈哈

-(id)initWithId:(NSString*)uid {
self = [super initWithClassName:@"Photo"];
[self setObjectId:targetID];

[self fetch];

self.prop1 = [self objectForKey:@"propertiseone"];
// other
}

答案 1 :(得分:-1)

使用@property (readwrite, retain)