More Related Content
Similar to Couchbase liteが更に使いやすくなってた
Similar to Couchbase liteが更に使いやすくなってた (8)
Couchbase liteが更に使いやすくなってた
- 2. 自己紹介
• 転職しました
• Couchbase Liteネタ担当
• iOSアプリ開発
• でも何故か今はOculus Riftやってます
• http://ssdkfk.wordpress.com/
• 前回のスライドは1023PV(9ヶ月で)
- 10. AppDelegate *ap = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// ドキュメントを追加
NSDictionary *contents =
@{@"text"
: @"Hello couchbase Lite",
@"check"
: [NSNumber numberWithBool:NO],
@"created_at" : [CBLJSON JSONObjectWithDate: [NSDate date]]};
// 無記名ドキュメントの取得
CBLDocument* doc = [ap.database untitledDocument];
// ドキュメントの追加
NSError* error;
if (![doc putProperties: contents error: &error]){
// 失敗
}
前回
AppDelegate *ap = ApplicationDelegate;
ExampleModel *model = [[ExampleModel alloc] initWithNewDocumentInDatabase:ap.database];
model.text = @"Hello CouchbaseLite!";
model.created_at = [NSDate new];
model.check = NO;
NSError *err;
if (![model save:&err]) {
NSLog(@"Save Error!");
}
今回
- 11. モデルクラス
ExampleModel.h
@interface ExampleModel : CBLModel
!
@property (nonatomic, copy) NSString *text;
@property (nonatomic, strong) NSDate *created_at;
@property (assign) BOOL check;
!
@end
ExampleModel.m
@implementation ExampleModel
!
@dynamic text,created_at,check;
!
@end
- 14. 具体的には
@class ExampleModel;
!
@interface SecondModel : CBLModel
!
@property (assign) ExampleModel *model1;
@property (nonatomic, copy) NSString *comment;
!
@end
{
text : "Hello CouchbaseLite!",
created_at : "2013-12-12",
check : false,
comment : "Wonderful!",
}
もちろん、コード内ではプロパティ通りに
クラスに格納されて返ってきます
使いやすい!
- 19. カスタム性
CBLTableDelegateで
- (UITableViewCell *)couchTableSource:(CBLUITableSource*)source
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
!
- (void)couchTableSource:(CBLUITableSource*)source
willUpdateFromQuery:(CBLLiveQuery*)query;
!
- (void)couchTableSource:(CBLUITableSource*)source
updateFromQuery:(CBLLiveQuery*)query
previousRows:(NSArray *)previousRows;
!
- (void)couchTableSource:(CBLUITableSource*)source
willUseCell:(UITableViewCell*)cell
forRow:(CBLQueryRow*)row;
!
- (bool)couchTableSource:(CBLUITableSource*)source
deleteRow:(CBLQueryRow*)row;
!
- (void)couchTableSource:(CBLUITableSource*)source
deleteFailed:(NSError*)error;
- 24. でもCouchDBと同じように実装すると
PushはできてもPullができない…
NSArray *repls = [ap.database replicateWithURL:[NSURL URLWithString:@"http://127.0.0.1:4984/sync_gateway"]
exclusively:YES];
!
self.pull = [repls objectAtIndex: 0];
self.push = [repls objectAtIndex: 1];
// completeではなく、modeを取得する
// completeの場合、completeしない場合があるため。
[_pull addObserver:self
forKeyPath:@"mode"
options:0
context:NULL];
[_push addObserver:self
forKeyPath:@"mode"
options:0
context:NULL];
- 27. できたそうです。
config.json
子、曰く
{
"interface":":4984",
"adminInterface":":4985",
"log":["REST"],
"databases":{
"sync_gateway":{
"server":"http://couchbase-jp:8091",
"bucket":"sync_gateway",
"sync":`function(doc) {channel(doc.channels);}`
},
"todo":{
"server":"http://couchbase-jp:8091",
"bucket":"todo",
"sync":`function(doc) {channel("public");}`,
"users": {
"GUEST": {
"disabled": false,
"admin_channels":["public"]
}
}
}
}
}