Cannot access property from a class which is subclassed from PFObject

307 views Asked by At

When I tried to get records from the local data store in iOS, objects are returning but if I access a custom property it gives an error "-[PFObject name]: unrecognized selector sent to instance". Below is a sample code snippet.

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
[query fromPinWithName:@"MyChanges"];

[[query findInBackground] continueWithBlock:^id(BFTask *task) {

  NSArray *scores = task.result;

  for (GameScore *score in scores) {
    NSLog(@"score is : %d %d", score.highScore, score.name);
  }
}];

and my subclass is like

@interface GameScore : PFObject <PFSubclassing>

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSNumber *highScore;

@end

And I am saving them as

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
  [GameScore pinAllInBackground:objects withName:@"MyChanges" block:^(BOOL succeeded, NSError *error) {

  }];
}];
1

There are 1 answers

1
dusker On BEST ANSWER

I had exact same issue as you, asked & answered it in this question: Parse local datastore and PFObject subclasses

Simply make sure you register your subclasses before doing anything else with Parse framework.