2014-08-27 47 views
0

当前,当用户第一次打开我的Parse应用程序时,将在Parse数据库上创建一个新的Installation对象,其中包含installationId和其他属性。如何使Parse安装对象的属性成为用户对象的指针?

一旦登录,它更新此Installation对象的userId属性与objectId串人的User对象。它只不过是一个字符串,恰好相当于各自的对象Id,但我想要的是它也是指向那个User对象的指针。

我试过将userId属性设置为一个指针而不是来自网站的字符串,但是这给了我一个错误信息,说明Error: invalid type for key userId, expected object, but got string,因为我的iOS代码以字符串形式发送它,而不是作为指向User类的指针。

如何让我的代码中的userId字符串指向User类?该文档是here,但我无法将其应用于此用例。

代码:

- (void)viewWillAppear:(BOOL)animated { 
    [super viewDidLoad]; 
    if ([PFUser currentUser]) { 
     NSLog(@"User is logged in"); 

     PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
     NSString *userId = [PFUser currentUser].objectId; 

     //userId[@"parent"] = [PFUser currentUser]; 

     [currentInstallation setObject:userId forKey: @"userId"]; 
     [currentInstallation saveInBackground]; 

    } else { 
     NSLog(@"User is not logged in"); 
     //[welcomeLabel setText:@"Not logged in"]; 
    } 
} 

回答

1

存储点,以在解析的对象的方式是整个对象保存到它。因此,请勿将userId存储在NSString中。只需执行以下操作:

- (void)viewWillAppear:(BOOL)animated { 
    [super viewDidLoad]; 
    if ([PFUser currentUser]) { 
     NSLog(@"User is logged in"); 

     PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
     PFUser* user = [PFUser currentUser]; 

     [currentInstallation setObject:user forKey: @"userId"]; 
     [currentInstallation saveInBackground]; 

    } else { 
     NSLog(@"User is not logged in"); 
     //[welcomeLabel setText:@"Not logged in"]; 
    } 
} 

这将导致解析以保存指向用户的指针。