1

Since it doesn't say in the docs or anywhere online, how do you set objects in custom classes? For example, you make a custom class named Friends, and it has three columns: user (string), added (relation), friends (relation). How would you set user within your app, for example?

2
  • What do you mean set user? Commented May 4, 2015 at 9:38
  • As in set the string "user" Commented May 4, 2015 at 17:07

1 Answer 1

4

PFObject subclassing is in the documentation: https://www.parse.com/docs/ios_guide#subclasses/iOS

You will need to:

  1. Create a custom class (see example below)
  2. Initialize the class in your AppDelegate.m (see example below)

Example custom subclass for parse.com, with 'Organization' as the Parse class name:

Organization.h

//
//  Organization.h
#import <Parse/Parse.h>

@interface Organization : PFObject<PFSubclassing>

+ (NSString *)parseClassName;

@property (retain) NSString *user;
@property (retain) NSString *addressLine1;
@property (retain) NSString *addressState;
@property (retain) NSString *addressZip;
@property (retain) NSString *phone;
@property (retain) NSString *email;
@property (retain) NSString *website;
@property (retain) NSString *contactFirstName;
@property (retain) NSString *contactLastName;
@property (retain) PFFile *logoImage;
@property (retain) NSString *orgDescription;
@property (retain) NSString *name;

@end

Organization.m

#import "Organization.h"
#import <Parse/PFObject+Subclass.h>

@implementation Organization

@dynamic addressCity;
@dynamic addressLine1;
@dynamic addressState;
@dynamic addressZip;
@dynamic phone;
@dynamic email;
@dynamic website;
@dynamic contactFirstName;
@dynamic contactLastName;
@dynamic logoImage;
@dynamic orgDescription;
@dynamic name;

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

@end

How to initialize in the AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [Organization registerSubclass]; //DO THIS BEFORE YOU START PARSE!
    [Parse setApplicationId:YOUR_ID clientKey:YOUR_KEY];

    ....
Sign up to request clarification or add additional context in comments.

8 Comments

What if I already made the class in Parse dashboard? Also, instead of PFObject, can my class be a subclass of UIViewController?
If you already made the class in the Parse dashboard, create your PFObject subclass to match what you have in Parse. You have to do that anyways; a PFObject subclass will only work if you have the same object in the database. // You can't use` UIViewController` as the superclass for a Parse object class; you have to use PFObject.
So I have to make a new class in my xcode project, and I would have to make an instance to the class (Organization for example) in my view controller to access it?
Correct - simply import the header of your PFObject into your .m file for your view controller and go :)
+ (NSString *)parseClassName; is a special function used by Parse's SDK. No need to change that one, but do change the + (NSString *)parseClassName function in the .m file to return @"Friends";
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.