realm simple
2015-07-19 16:01
155 查看
Realm Objective-C
The documentation can be found at realm.io/docs/objc/latest. The API reference is located at realm.io/docs/objc/latest/api.
https://realm.io/cn/docs/objc/latest/
The documentation can be found at realm.io/docs/objc/latest. The API reference is located at realm.io/docs/objc/latest/api.
https://realm.io/cn/docs/objc/latest/
@interface Person : RLMObject @property NSString *name; @property RLMArray<Dog> *dogs; @end @implementation Person @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[UIViewController alloc] init]; [self.window makeKeyAndVisible]; [[NSFileManager defaultManager] removeItemAtPath:[RLMRealm defaultRealmPath] error:nil]; // Create a standalone object Dog *mydog = [[Dog alloc] init]; // Set & read properties mydog.name = @"Rex"; mydog.age = 9; NSLog(@"Name of dog: %@", mydog.name); // Realms are used to group data together RLMRealm *realm = [RLMRealm defaultRealm]; // Create realm pointing to default file // Save your object [realm beginWriteTransaction]; [realm addObject:mydog]; [realm commitWriteTransaction]; // Query RLMResults *results = [Dog objectsInRealm:realm where:@"name contains 'x'"]; // Queries are chainable! RLMResults *results2 = [results objectsWhere:@"age > 8"]; NSLog(@"Number of dogs: %li", (unsigned long)results2.count); // Link objects Person *person = [[Person alloc] init]; person.name = @"Tim"; [person.dogs addObject:mydog]; [realm beginWriteTransaction]; [realm addObject:person]; [realm commitWriteTransaction]; // Multi-threading dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ RLMRealm *otherRealm = [RLMRealm defaultRealm]; RLMResults *otherResults = [Dog objectsInRealm:otherRealm where:@"name contains 'Rex'"]; NSLog(@"Number of dogs: %li", (unsigned long)otherResults.count); }); ----------
相关文章推荐
- realm tableview
- Objective C中数组排序几种情况的总结
- SQL脚本积累之三-----case....when...的使用示例
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第九讲:块元素、行内元素、标准流、盒子模型
- 黑马程序员 About Me
- php实现网站顶踩功能的完整前端代码
- leetcode239:Sliding Window Maximum
- 欢迎使用CSDN-markdown编辑器
- 百度,360 你们谁是骗子?
- 编程中应注意的细节
- hdu 2141 Can you find it? 二分
- CAS
- Swap Nodes in Pairs
- 算法总结——spfa(使用优先队列的Bellman_Ford算法)
- Struts2乱码问题的解决办法
- Ubuntu输入密码登陆后又跳回到登录界面
- JavaScript--DOM修改元素的属性
- 黑马程序员——Java反射&动态代理
- 龙贝格算法
- 关于ListView中ViewHolder修饰符的问题