iosobjective-cparse-platformlocal-datastore

Can't Query for Pinned Subclassed PFObject in localDatastore


Hello I'm having trouble retrieving a PFObject subclass from the Parse LocalDataStore, I have NSLogged the object before pinning and it looks fine, it is also successfully pinning. But when I go to Query for the object after pinning it, nothing is turning up.

Heres my code below. Can someone help me retrieve my objects?

Thanks in advance.

Job.h

@interface Job : PFObject<PFSubclassing>

/* Set up all properties that we'll need to record jobs */

// Job Details Properties
@property (retain) NSString *name;
@property (retain) NSString *identifier;
@property (retain) NSString *contact;
@property (retain) NSString *address;
@property (retain) NSString *postcode;

+ (NSString *)parseClassName;

@end

----

Job.m

#import "Job.h"
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>

@implementation Job

@dynamic name;
@dynamic identifier;
@dynamic contact;
@dynamic address;
@dynamic postcode;

+ (NSString *)parseClassName {

  return @"Jobs";
}


@end

----

MyJobsController.m

#import "MyJobsController.h"
#import "Job.h"

@implementation MyJobsController

- (IBAction)addJob:(id)sender {

    Job *jobOne = [[Job alloc] init];

    jobOne.name = @"Company 001";
    jobOne.contact = @"Dave";
    jobOne.identifier = @"001";

    [jobOne pinInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {

        if (succeeded) {

            NSLog(@"Pinned job: %@",job); 

            [self getJobs];           

        }else{

            NSLog(@"Error: %@",error.userInfo);
        }        

 }];
}

- (void)getJobs {

PFQuery *query = [Job query];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {

      NSLog(@"Found Jobs: %@",objects);

    }else{

      NSLog(@"Error: %@",error.userinfo);

    }
  }]; 
}   

----

MyJobsController.h

#import <UIKit/UIKit.h>

@interface MyJobsController : UIViewController

- (IBAction)addJob:(id)sender;

@end

Solution

  • Have you seen this api information from parse.com https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/pinInBackgroundWithBlock: As far as i understand you have to change the source of this query to all pinned objects. [PFQuery fromLocalDatastore] or you can create an unfetched pointer with [PFObject objectWithoutDataWithClassName:objectId:] and then call fetchFromLocalDatastore on it. Reference info for fromLocalDatastore https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/fromLocalDatastore

    Hope that helps.