Couchbase LiteをCBLDocumentベースで更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)updateDocument:(NSIndexPath *)indexPath{ | |
// check情報を取得 | |
NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithDictionary:dataArray[indexPath.row]]; | |
// 現在のチェックを受け取る | |
BOOL wasChecked = [[dataDic valueForKey:@"check"] boolValue]; | |
// 結果を反転させてセットする | |
[dataDic setObject: [NSNumber numberWithBool: !wasChecked] forKey:@"check"]; | |
// Updateを準備する | |
NSError *err; | |
AppDelegate *ap = ApplicationDelegate; | |
CBLDocument *doc = [ap.database documentWithID:[dataDic objectForKey:@"_id"]]; | |
// Update実行 | |
if (![doc putProperties:dataDic error: &err]){ | |
[self showErrorAlert: @"Couldn't update the item"]; | |
} | |
else{ | |
NSLog(@"Update Complete!"); | |
[self loadAllDocuments]; | |
[self.tableView reloadData]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment