Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a pointer field to a subclass of PFUser

I'd like to add a pointer field to my PFUser subclass, managed by the PFUser subclass. Ideally, the pointer object would be available automatically on the PFUser subclass - saved and fetched when the user is saved and fetched.

With any other PFObject subclass, I would simply add a Dynamic property and be sure to use includeKey when querying.

However, for a PFUser subclass, I'm never actually querying. How can I force the pointer object to fetch?

like image 310
chris stamper Avatar asked Jul 06 '15 18:07

chris stamper


1 Answers

It's an easy, two-step process in objective-c, even with a subclassed :

  1. Create a local object that represents the pointer, even though you don't have the data yet
  2. Use fetchIfNeededInBackground to populate the pointer object locally

    PFObject *yourPointerObject = [[PFUser currentUser] objectForKey"pointerKey"];
    [yourPointerObject fetchIfNeededInBackground];
    
like image 138
Ryan Kreager Avatar answered Nov 16 '22 10:11

Ryan Kreager