如何避免不同的用戶將同一個字符串保存到同一列?如果對象已經創建,它需要檢查特定列...解析iOS對象複製
我不試圖爲PFUser類,以檢查重複的用戶,它的默認值。
任何代碼線索,開始的例子?
下面是我保存對象的代碼。字段_channelName是不能重複的字段,必須在保存前檢查。
- (IBAction)addButton:(id)sender {
// Create a new Post object and create relationship with PFUser
PFObject *newPost = [PFObject objectWithClassName:@"Channel"];
[newPost setObject:[_textView text] forKey:@"about"];
[newPost setObject:[_channelName text] forKey:@"name"];
[newPost setObject:[_enterKey text] forKey:@"enterkey"];
[newPost setObject:[PFUser currentUser] forKey:@"owner"]; // One-to-Many relationship created here!
NSData *imageData = UIImageJPEGRepresentation(self.channelImage.image, 0.8);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];
[newPost setObject:imageFile forKey:@"image"];
// Set ACL permissions for added security
PFACL *postACL = [PFACL ACL];
[postACL setPublicReadAccess:YES];
[PFACL setDefaultACL:postACL withAccessForCurrentUser:YES];
//PFACL *postACL = [PFACL ACLWithUser:[PFUser currentUser]];
[postACL setPublicReadAccess:YES];
[newPost setACL:postACL];
// Save new Post object in Parse
[newPost saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
[self dismissViewControllerAnimated:YES completion:nil];
// Dismiss the viewController upon success
} else {
//implement upload error message
}
}];
[self dismissViewControllerAnimated:YES completion:nil];
}
感謝名單和歡呼!!!!
你可以發佈一個示例對象嗎?默認情況下,Parse會在每次實例化並保存一個對象時創建一個新對象,除非您已查詢或特別引用某些對象。代碼示例將幫助你:) –
是的,當然沒有問題!只要我接近我的項目,我會在問題中發佈並再次與您聯繫。 –
嘿@RyanKreager我編輯了我的問題。請試一試 –