简体   繁体   中英

Parse local datastore and PFObject subclasses

So I was delighted when Parse local data store got introduced in iOS and quickly added couple of functionalities using it. In one place i persist certain collection of objects using

[Spot pin] 

FYI Spot is a subclass of PFObject. Now, i open up another screen where that object that i just persisted is part of the PFQuery result, however i keep getting exception:

[PFObject name]: unrecognized selector sent to instance 0x7fd2716422e0

Looks like Parse in this case is referencing the pinned object as their doc states:

When enabled, there will only be one instance of any given PFObject. For example, imagine you have an instance of the "GameScore" class with an objectId of "xWMyZ4YEGZ", and then you issue a PFQuery for all instances of "GameScore" with that objectId. The result will be the same instance of the object you already have in memory.

but rather than my subclass it's thinking it's just a PFObject... is there any way to deal with it?

Figured this one out myself. Turns out you have to call registerSubclass method on the subclasses BEFORE you even initialize Parse with it's AppId and clientKey and enable localDataStore. So the code should look:

[Spot registerSubclass];
[Parse setApplicationId:@"XXX" clientKey:@"XXX"];
[Parse enableLocalDatastore];

... call [Parse enableLocalDatastore] before your call to setApplicationId:clientKey:

- (void)application:(UIApplication *)application didFinishLaunchWithOptions:(NSDictionary *)options {
  [Parse enableLocalDatastore];
  [Parse setApplicationId:@"parseAppId" clientKey:@"parseClientKey"];
}

https://www.parse.com/docs/ios/guide#local-datastore-pinning

and in .m of your Spot subclass:

+ (void)load{

    [self registerSubclass];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM