Skip to content

Instantly share code, notes, and snippets.

@kuetsuhara
Created December 16, 2013 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuetsuhara/7981520 to your computer and use it in GitHub Desktop.
Save kuetsuhara/7981520 to your computer and use it in GitHub Desktop.
Couchbase LiteをCBLDocumentベースで更新
- (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