Search code examples
objective-cparse-platformpfobject

Setting parse pointer without PFObject? (have objectId)


ObjectA has a PFPointer (lets call it pointerToB) to an ObjectB. Now if I want to create a new instance:

PFObject *newA = [PFObject objectWithClassName:@"ObjectA"];

is there any way to set pointerToB without the actual PFObject *objectB?

I'm wrapping the PFObjects into my own model classes to persist and I store the objectIds.

I'd really like to avoid making a call to Parse to retrieve the objectB when I already have the objectId.

Any way of doing something like:

PFObject *newA = [PFObject objectWithClassName:@"ObjectA"];
newA[@"pointerToB"] = persistedObject.parseObjectId; // This is a string, but it identifies the actual ObjectB object in Parse.

Solution

  • You can use +PFObject.objectWithoutDataWithClassName:(NSString *)className objectId:(NSString *)objectId

    That returns an object without any data but you can set it to the pointer of the object and it will work.

    If you need to fetch it's data you can just call -fetch on that object.

    Reference