无法在localDatastore中查询固定的Subclassed PFObject

时间:2015-11-01 11:36:11

标签: ios objective-c parse-platform local-datastore

您好我从Parse LocalDataStore检索PFObject子类时遇到问题,我在固定之前已经对NSLog了对象,它看起来很好,它也成功固定。但是当我在固定它之后去查询对象时,没有任何东西出现。

下面是我的代码。有人可以帮我找回我的物品吗?

提前致谢。

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

1 个答案:

答案 0 :(得分:0)

您是否从parse.com https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/pinInBackgroundWithBlock看到了这个api信息:据我所知,您必须将此查询的来源更改为所有固定对象。 [PFQuery fromLocalDatastore]或者您可以使用[PFObject objectWithoutDataWithClassName:objectId:]创建一个未获取的指针,然后在其上调用fetchFromLocalDatastorefromLocalDatastore的参考信息 https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/fromLocalDatastore

希望有所帮助。