2014-08-27 46 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"]; 
    } 
} 

這將導致解析以保存指向用戶的指針。