PFObject(Subclass)

@interface PFObject (Subclass)

Subclassing Notes

Developers can subclass PFObject for a more native object-oriented class structure. Strongly-typed subclasses of PFObject must conform to the PFSubclassing protocol and must call PFSubclassing.+registerSubclass before Parse.+setApplicationId:clientKey: is called. After this it will be returned by PFQuery and other PFObject factories.

All methods in PFSubclassing except for PFSubclassing.+parseClassName are already implemented in the PFObject(Subclass) category.

Including PFObject+Subclass.h in your implementation file provides these implementations automatically.

Subclasses support simpler initializers, query syntax, and dynamic synthesizers. The following shows an example subclass:

\@interface MYGame : PFObject <PFSubclassing>

// Accessing this property is the same as objectForKey:@"title"
@property (nonatomic, copy) NSString *title;

+ (NSString *)parseClassName;

@end


@implementation MYGame

@dynamic title;

+ (NSString *)parseClassName {
    return @"Game";
}

@end


MYGame *game = [[MYGame alloc] init];
game.title = @"Bughouse";
[game saveInBackground];
  • Creates an instance of the registered subclass with this class’s PFSubclassing.+parseClassName.

    This helps a subclass ensure that it can be subclassed itself. For example, [PFUser object] will return a MyUser object if MyUser is a registered subclass of PFUser. For this reason, [MyClass object] is preferred to [[MyClass alloc] init]. This method can only be called on subclasses which conform to PFSubclassing. A default implementation is provided by PFObject which should always be sufficient.

    Declaration

    Objective-C

    + (nonnull instancetype)object;
  • Creates a reference to an existing PFObject for use in creating associations between PFObjects.

    Calling dataAvailable on this object will return NO until -fetchIfNeeded or -fetch has been called. This method can only be called on subclasses which conform to PFSubclassing. A default implementation is provided by PFObject which should always be sufficient. No network request will be made.

    Declaration

    Objective-C

    + (nonnull instancetype)objectWithoutDataWithObjectId:
            (nullable NSString *)objectId;

    Parameters

    objectId

    The object id for the referenced object.

    Return Value

    An instance of PFObject without data.

  • Registers an Objective-C class for Parse to use for representing a given Parse class.

    Once this is called on a PFObject subclass, any PFObject Parse creates with a class name that matches [self parseClassName] will be an instance of subclass. This method can only be called on subclasses which conform to PFSubclassing. A default implementation is provided by PFObject which should always be sufficient.

    Declaration

    Objective-C

    + (void)registerSubclass;
  • Returns a query for objects of type PFSubclassing.+parseClassName.

    This method can only be called on subclasses which conform to PFSubclassing. A default implementation is provided by PFObject which should always be sufficient.

    See

    PFQuery

    Declaration

    Objective-C

    + (nullable PFQuery *)query;
  • Returns a query for objects of type PFSubclassing.+parseClassName with a given predicate.

    A default implementation is provided by PFObject which should always be sufficient. - warning: This method can only be called on subclasses which conform to PFSubclassing.

    Declaration

    Objective-C

    + (nullable PFQuery *)queryWithPredicate:(nullable NSPredicate *)predicate;

    Parameters

    predicate

    The predicate to create conditions from.

    Return Value

    An instance of PFQuery.