{"id":91647,"date":"2015-06-27T10:02:03","date_gmt":"2015-06-27T01:02:03","guid":{"rendered":"http:\/\/www.key-p.com\/blog\/staff\/?p=91647"},"modified":"2015-06-27T10:04:26","modified_gmt":"2015-06-27T01:04:26","slug":"realm%ef%bc%88%e5%88%a9%e7%94%a8%e7%b7%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.key-p.com\/blog\/staff\/archives\/91647","title":{"rendered":"Realm\uff08\u5229\u7528\u7de8\uff09"},"content":{"rendered":"<p>\n\u4eca\u56de\u306f\u3001Realm\u8a18\u4e8b\u306e\u7b2c\uff12\u5f3e\u3092\u6295\u7a3f\u3057\u307e\u3059\u3002<br \/>\n\u524d\u56de\u306e\u6295\u7a3f\u304b\u3089\u3001\u304b\u306a\u308a\u65e5\u6570\u304c\u7d4c\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3059\u304c\u2026<br \/>\n\u4eca\u56de\u306f\u3001\u5b9f\u969b\u306e\u4f7f\u3044\u65b9\u3002<br \/>\n<!--more--><br \/>\nSQLite\u540c\u69d8\u306bDB\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304b\u3089\u59cb\u307e\u308a\u307e\u3059\u3002<br \/>\n<br \/>\n<span style=\"color: #3366ff;\"><strong>DB\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/strong><\/span><br \/>\n<pre class=\"lang:default decode:true\">RLMRealm *realm = [RLMRealm defaultRealm];<\/pre>\n\u3053\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3053\u3068\u3067\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u306bdefault.realm\u3068\u3044\u3046DB\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<br \/>\nDB\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u3066\u751f\u6210\u3057\u305f\u3044\u5834\u5408\u306f\u3001<br \/>\n<pre class=\"lang:default decode:true\">[RLMRealm setDefaultRealmPath:@\u201c..\/Documents\/hoge.realm\u201d];\nRLMRealm *realm = [RLMRealm defaultRealm];<\/pre>\n\u306a\u611f\u3058\u3067\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u30d1\u30b9\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3001DB\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<br \/>\n\uff08\u3053\u306e\u5834\u5408\u306f\u3001hoge.realm\uff09<br \/>\n<br \/>\n<span style=\"color: #3366ff;\"><strong>\u30e2\u30c7\u30eb\u306e\u4f5c\u6210<\/strong><\/span><br \/>\n\u5b9f\u969b\u306bDB\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u5f8c\u306f\u3001\u30c6\u30fc\u30d6\u30eb\uff08\u30e2\u30c7\u30eb\uff09\u306e\u4f5c\u6210\u3067\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u300c\u304a\u6c17\u306b\u5165\u308a\u300d\u3092\u7ba1\u7406\u3059\u308b\u30e2\u30c7\u30eb\u306e\u5834\u5408\u306e\u30e2\u30c7\u30eb\u4f8b\u3060\u3068\u3053\u306e\u69d8\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<pre class=\"lang:default decode:true\">@interface Favorite : RLMObject\n@property NSInteger id;\n@property NSString *name;\n@end\n\n@implementation Favorite\n+ (NSString *)primaryKey {\nreturn @\"id\";\n}\n@end<\/pre>\n<span style=\"color: #3366ff;\"><strong>\u30c7\u30fc\u30bf\u306e\u65b0\u898f\u8ffd\u52a0<\/strong><\/span><br \/>\n\u4e0a\u306e\u30e2\u30c7\u30eb\u300c\u304a\u6c17\u306b\u5165\u308a\u300d\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306f<br \/>\n<pre class=\"lang:default decode:true\">Favorite *favorite = [[Favorite alloc] init];\nfavorite.id = 1;\nfavorite.name = @\u201cBest Favorite\u201d;\n\nRLMRealm *realm = [RLMRealm defaultRealm];\n\n[realm beginWriteTransaction];\n[realm addObject:favorite];\n[realm commitWriteTransaction];<\/pre>\n\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u6a5f\u80fd\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3001\u7d04\u675f\u3054\u3068\u3068\u306e\u3053\u3068\u3067\u3059\u3002<br \/>\n<br \/>\n<span style=\"color: #3366ff;\"><strong>\u30c7\u30fc\u30bf\u306e\u691c\u7d22<\/strong><\/span><br \/>\n\u691c\u7d22\u7d50\u679c\u306f\u3001RLMResults\u3068\u3044\u3046\u578b\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br \/>\n<pre class=\"lang:default decode:true\">RLMResults *favorites = [Favorite allObjects];<\/pre>\n\u3067Favorite\u30e2\u30c7\u30eb\u306e\u5168\u4ef6\u53d6\u5f97<br \/>\n\u691c\u7d22\u6761\u4ef6\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408\u306f<br \/>\n<pre class=\"lang:default decode:true\">NSPredicate *pre = [NSPredicate predicateWithFormat:@\u201cname = %@\u201d, @\u201choge\u201d];\nRLMResults *favorite = [Favorite objectsWithPredicate:pre];<\/pre>\n<br \/>\n<span style=\"color: #3366ff;\"><strong>\u30c7\u30fc\u30bf\u306e\u66f4\u65b0<\/strong><\/span><br \/>\n<pre class=\"lang:default decode:true\">Favorite *favorite = [[Favorite alloc] init];\nfavorite.id = 1;\nfavorite.name = @\u201cBetter Favorite\u201d;\n\n[realm beginWriteTransaction];\n[Favorite createOrUpdateInRealm:realm withObject:favorite];\n[realm commitWriteTransaction];<\/pre>\n<pre class=\"lang:default decode:true\">+[RLMObject createOrUpdateInRealm:withObject:]<\/pre>\n\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u4e3b\u30ad\u30fc\u3068\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u304c\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002<br \/>\n\uff08\u4e3b\u30ad\u30fc\u3068\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u304c\u306a\u3044\u5834\u5408\u306f\u3001\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002\uff09<br \/>\n<br \/>\n<span style=\"color: #3366ff;\"><strong>\u30c7\u30fc\u30bf\u306e\u524a\u9664<\/strong><\/span><br \/>\n\u30c7\u30fc\u30bf\u306e\u524a\u9664\u3082\u3001\u7279\u306b\u96e3\u3057\u304f\u306a\u304f<br \/>\n<pre class=\"lang:default decode:true\">[realm beginWriteTransaction];\n[Favorite deleteObject:favorite];\n[realm commitWriteTransaction];<\/pre>\n<br \/>\n\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068\u3057\u3066\u306f\u4ee5\u4e0a\u3067\u3059\u3002<br \/>\n\u30c7\u30fc\u30bf\u53d6\u5f97\u90e8\u5206\u3067\u3001\u4ef6\u6570\u6307\u5b9a\u3067\u306e\u30c7\u30fc\u30bf\u53d6\u5f97\u7b49\u3082\u5b9f\u884c\u3057\u3066\u307f\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001Realm\u5074\u306b\u305d\u306e\u69d8\u306a\u30e1\u30bd\u30c3\u30c9\u306f\u6e96\u5099\u3055\u308c\u3066\u3044\u306a\u3044\u69d8\u5b50\u3067\u3057\u305f\u3002<br \/>\n\u30ed\u30b8\u30c3\u30af\u5074\u3067\u51e6\u7406\u3059\u308b\u306a\u308a\u3001\u30e2\u30c7\u30eb\u8a2d\u8a08\u6bb5\u968e\u3067\u89e3\u6c7a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306f\u3001Realm\u8a18\u4e8b\u306e\u7b2c\uff12\u5f3e\u3092\u6295\u7a3f\u3057\u307e\u3059\u3002 \u524d\u56de\u306e\u6295\u7a3f\u304b\u3089\u3001\u304b\u306a\u308a\u65e5\u6570\u304c\u7d4c\u3063\u3066 &hellip; <a href=\"https:\/\/www.key-p.com\/blog\/staff\/archives\/91647\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,10],"tags":[],"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/91647"}],"collection":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/comments?post=91647"}],"version-history":[{"count":3,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/91647\/revisions"}],"predecessor-version":[{"id":91650,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/91647\/revisions\/91650"}],"wp:attachment":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/media?parent=91647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/categories?post=91647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/tags?post=91647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}