{"id":1422,"date":"2013-03-20T23:37:14","date_gmt":"2013-03-20T14:37:14","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=1422"},"modified":"2021-06-07T22:45:24","modified_gmt":"2021-06-07T13:45:24","slug":"coredata-%e3%81%ae-or%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc-magicalrecord-%e3%82%92%e4%bd%bf%e3%81%86","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/coredata-%e3%81%ae-or%e3%83%9e%e3%83%83%e3%83%91%e3%83%bc-magicalrecord-%e3%82%92%e4%bd%bf%e3%81%86\/","title":{"rendered":"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/magicalpanda\/MagicalRecord\" target=\"_blank\" rel=\"noopener noreferrer\">magicalpanda\/MagicalRecord<\/a><\/p>\n<p>CoreData \u306e ORM\u3067\u3042\u308b MagicalRecord \u306e\u5c0e\u5165\u30e1\u30e2\u3002<\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u540d\u306f Rails \u306b\u8fd1\u3044\u611f\u3058\u3067\u3059\u3002\u4f55\u3088\u308a MagicalRecord \u3063\u3066\u3044\u3046\u540d\u524d\u304c\u304a\u6c17\u306b\u5165\u308a\u306a\u306e\u3067\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u5c0e\u5165<\/h2>\n<p>\u52d5\u4f5c\u6761\u4ef6\u306f\u3001<\/p>\n<blockquote><p>MagicalRecord Platform Requirements:<\/p>\n<p>iOS5.x or newer, or Mac OS 10.7 and newer<br \/>\nARC<\/p><\/blockquote>\n<p>\u3068\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>CocoaPods \u304c\u4f7f\u3048\u307e\u3059\u3002Podfile \u306b\u8ffd\u52a0\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n<h4>Podfile<\/h4>\n<pre lang=\"ruby\">platform :ios, '6.1'\npod 'MagicalRecord'<\/pre>\n<pre lang=\"bash\">% pod install<\/pre>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e .pch \u30d5\u30a1\u30a4\u30eb &quot;{\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d}-Prefix.pch&quot; \u3067 MagicalRecord \u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<h4>{\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d}-Prefix.pch<\/h4>\n<pre lang=\"objc\">#import <availability .h>\n\n#ifndef __IPHONE_5_0\n#warning \"This project uses features only available in iOS SDK 5.0 and later.\"\n#endif\n\n#ifdef __OBJC__\n    #import <uikit \/UIKit.h>\n    #import <foundation \/Foundation.h>\n\n    #define MR_SHORTHAND\n    #import \"CoreData+MagicalRecord.h\"\n#endif<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u8aad\u307f\u3053\u3081\u3070OK\u3067\u3059\u3002MR_SHORTHAND \u3092\u8ffd\u52a0\u3059\u308b\u3068\u3001\u77ed\u3044\u30e1\u30bd\u30c3\u30c9\u540d\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306b\u3001Build Phases \u306e\u8a2d\u5b9a\u304b\u3089\u3001Link Binary With Libraries \u3078 <code>CoreData.framework<\/code> \u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001ApplicationDelegate.m \u306e\u8d77\u52d5\u51e6\u7406\u3042\u305f\u308a\u3067\u3001\u521d\u671f\u5316\u51e6\u7406\u3092\u547c\u3079\u3070\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<pre lang=\"objc\">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n    \/\/ \u521d\u671f\u5316\u51e6\u7406\n    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@\"nakamoto.sql\"];\n    return YES:\n}<\/pre>\n<h2>\u4f7f\u3044\u65b9<\/h2>\n<h3>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4fdd\u5b58<\/h3>\n<p>CoreData \u3067\u306e\u30e2\u30c7\u30eb\u306e\u4f5c\u308a\u65b9\u306f\u901a\u5e38\u3068\u540c\u69d8\u3067\u3059\u3002Photo(photoId: Integer32, comment: String, tag: String) \u3068\u304b\u30c6\u30ad\u30c8\u30a6\u306b\u4f5c\u3063\u3066\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre lang=\"objc\">NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];\n\nPhoto* photo = [Photo MR_createEntity];\nphoto.photoId = [NSNumber numberWithInt:\"121\"];\nphoto.comment = @\"\u5317\u6975\u305f\u3079\u307e\u3059\";\nphoto.tag     = @\"ramen\";\nNSError* error;\n[photo save:error];<\/pre>\n<h3>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u53d6\u5f97<\/h3>\n<p>1\u3064\u53d6\u5f97<\/p>\n<pre lang=\"objc\">Photo *photo = [Photo findFirstByAttribute:@\"photoId\" withValue:[NSNumber numberWithInt:\"121\"]];<\/pre>\n<p>\u5168\u90e8\u53d6\u5f97<\/p>\n<pre lang=\"objc\">NSArray *photos = [Photo findByAttribute:@\"tag\" withValue:@\"ramen\"];<\/pre>\n<h3>\u66f4\u65b0<\/h3>\n<pre lang=\"objc\">NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];\nPhoto *photo = [Photo findFirstByAttribute:@\"photoId\" withValue:[NSNumber numberWithInt:\"121\"]];\nphoto.comment = @\"\u3059\u307f\u307e\u305b\u3093\u3002\u51b7\u3084\u3057\u5473\u564c\u306b\u3057\u3066\u3082\u3044\u3044\u3067\u3059\u304b\uff1f\";\nNSError* error;\n[context save:error]<\/pre>\n<h3>\u524a\u9664<\/h3>\n<pre lang=\"objc\">Photo *photo = [Photo findFirstByAttribute:@\"photoId\" withValue:[NSNumber numberWithInt:\"121\"]];\n[photo deleteEntity];<\/pre>\n<p>\u6614\u4f7f\u3063\u3066\u305f\u3068\u304d\u306f\u3001 save \u3060\u3068\u4e0a\u624b\u304f\u3044\u304b\u306a\u3044\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u3063\u3066 saveNestedContexts \u3092\u4f7f\u3063\u3066\u305f\u3093\u3060\u3051\u3069\u3001\u4eca\u306e\u6700\u65b0\u7248\u306e 2.1 \u3060\u3068 deprecated \u306b\u306a\u3063\u3066\u305f\u306e\u3067 save \u3092\u4f7f\u3063\u3068\u3053\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRecord \u306e\u5c0e\u5165\u30e1\u30e2\u3002 \u30e1\u30bd\u30c3\u30c9\u540d\u306f Rails \u306b\u8fd1\u3044\u611f\u3058\u3067\u3059\u3002\u4f55\u3088\u308a MagicalRecord \u3063\u3066\u3044\u3046\u540d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1483,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[35,12,27],"class_list":["post-1422","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-ios","tag-mac","tag-objective-c"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=1422"}],"version-history":[{"count":34,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1422\/revisions"}],"predecessor-version":[{"id":3838,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1422\/revisions\/3838"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/1483"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=1422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=1422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=1422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}