简体   繁体   中英

PFQuery of a registered subclass causing an NSInternalInconsistencyException

I've had a smooth time with Parse until this point. I'm currently having a snippet of code below.

// Retrieve all ride requests
PFQuery *query = [RideRequest query];
[query includeKey:@"customer"];
[query whereKey:@"status" equalTo:@(RIDE_REQUESTED)];
[query orderByDescending:@"numberOfPeople"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    rides = objects;
}];

The block above is never entered as I receive the following error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "numberOfPeople" has no data. Call fetchIfNeeded before getting its value.'

RideRequest is a registered subclass. The class interface is what you see below in its basic form.

@class User
@interface RideRequest : PFObject<PFSubclassing>

@property (nonatomic, strong) User *customer;
@property (nonatomic) int status;
@property (nonatomic, strong) NSString *numberOfPeople;

User is a registered subclass of PFUser.

@class RideRequest
@interface User : PFUser<PFSubclassing>

@property (nonatomic, strong) RideRequest *rideRequest;

I have other subclassed pfobjects that don't have any problem performing a PFQuery however none of those have a reference to User (the subclass of PFUser). I'm assuming that it may be related to why I'm seeing this issue. I'm not sure why the key 'numberOfPeople' is being called out as needing to be fetched. It is not a pointer to a PFObject. So it's a bit confusing. Any help would be greatly appreciated.

Solved my own question. I was overriding the init method on my custom PFObject subclass. Removing the -(instancetype)init method from my implementation and adding my own custom initializer helped remediate the issue. Turns out that PFQuery calls the init method in its implementation when generating the objects for the NSArray it returns (Or at least this is what it appears to be doing).

Also as a note, I've noticed that debugging from the simulator was giving me a more detailed stacktrace then from debugging from my device. Not sure if this is parse related or not.

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