pizzafilms
pizzafilms

Reputation: 4019

How to initialize PFObject subclass when fetched?

The Parse docs specifically state that you should not override init for subclasses of PFObject. That's okay for objects that are created in code because you can override the object method, like this...

@implementaion CustomObject : PFObject <Subclassing>

+ (instancetype) object {
    CustomObject *me = [super object];

    // init some instance variables or whatever

    return me;
}

@end

This works when for this case: CustomObject *myThing = [CustomObject object];

But object does not seem to be called when fetching an object from a query....

PFQuery *query = [CustomObject query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        for(int i = 0; i < objects.count; i++){
            CustomObject *myThing = objects[i];
            // object method was never called...
        }
    }
}];

So...how can I initialize a custom PFObject when it's fetched?

Upvotes: 2

Views: 1158

Answers (1)

Zhanserik Kenes
Zhanserik Kenes

Reputation: 335

Probably you have not registered your subclass.

Just call [CustomObject register] before

[Parse setApplicationId:@"your id"
                  clientKey:@"your key"];

or add to subclass

+ (void) load{
    [self register];
}

Upvotes: 1

Related Questions