导致 NSInternalInconsistencyException 的已注册子类的 PFQuery

PFQuery of a registered subclass causing an NSInternalInconsistencyException

到目前为止,我对 Parse 的使用一直很顺利。我目前在下面有一段代码。

// 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;
}];

上面的块从未输入,因为我收到以下错误 由于未捕获的异常 'NSInternalInconsistencyException',正在终止应用程序,原因:'Key "numberOfPeople" has no data. Call fetchIfNeeded before getting its value.'

RideRequest 是一个注册子class。 class 界面是您在下面看到的基本形式。

@class User
@interface RideRequest : PFObject<PFSubclassing>

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

用户是 PFUser 的注册子class。

@class RideRequest
@interface User : PFUser<PFSubclassing>

@property (nonatomic, strong) RideRequest *rideRequest;

我还有其他 subclassed pfobjects,它们在执行 PFQuery 时没有任何问题,但是 none 其中有对 User 的引用(PFUser 的 subclass) .我假设这可能与我看到此问题的原因有关。我不确定为什么需要获取密钥 'numberOfPeople' 。它不是指向 PFObject 的指针。所以这有点令人困惑。任何帮助将不胜感激。

解决了我自己的问题。我在我的自定义 PFObject 子类上重写了 init 方法。从我的实现中删除 -(instancetype)init 方法并添加我自己的自定义初始化程序有助于解决问题。事实证明,当为 NSArray it returns 生成对象时,PFQuery 在其实现中调用了 init 方法(或者至少这是它看起来正在做的)。

另请注意,我注意到从模拟器进行调试比从我的设备进行调试为我提供了更详细的堆栈跟踪信息。不确定这是否与解析相关。