Saving PFObject NSCoding

后端 未结 4 2203
清歌不尽
清歌不尽 2021-02-14 07:45

My Problem: saveInBackground isn\'t working.

The Reason It\'s not working: I\'m saving PFObjects stored in an

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-14 07:57

    PFObject doesn't implement NSCoding, and it looks like the library you're using isn't encoding the object properly, so your current approach won't work.

    The approach recommended by Parse is to cache your PFQuery objects to disk by setting the cachePolicy property:

    PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
    query.cachePolicy = kPFCachePolicyNetworkElseCache;
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
      if (!error) {
        // Results were successfully found, looking first on the
        // network and then on disk.
      } else {
        // The network was inaccessible and we have no cached data for
        // this query.
      }
    }];
    

    (Code from the Caching Queries documentation.)

    Then your app will load from the cache. Switch to kPFCachePolicyCacheElseNetwork if you want to try the disk cache first (faster, but possibly out of date.)

    Your query object's maxCacheAge property sets how long something will stay on disk before it expires.


    Alternatively, there's a PFObject category by Florent here that adds NSCoder support to PFObject. It's different than the implementation in the library you linked to, but I'm not sure how reliable it is. It may be worth experimenting with.

提交回复
热议问题