{"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":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"\u3061\u3085\u3046\"\/>\n\t<link rel=\"canonical\" href=\"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\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" \/>\n\t\t<meta property=\"og:site_name\" content=\"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:description\" content=\"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec\" \/>\n\t\t<meta property=\"og:url\" content=\"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\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t\t<meta property=\"og:image:height\" content=\"240\" \/>\n\t\t<meta property=\"article:tag\" content=\"development\" \/>\n\t\t<meta property=\"article:tag\" content=\"ios\" \/>\n\t\t<meta property=\"article:tag\" content=\"mac\" \/>\n\t\t<meta property=\"article:tag\" content=\"objective-c\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2013-03-20T14:37:14+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-06-07T13:45:24+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:title\" content=\"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","description":"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec","canonical_url":"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\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"ja_JP","og:site_name":"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:type":"article","og:title":"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:description":"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec","og:url":"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\/","og:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg","og:image:secure_url":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg","og:image:width":400,"og:image:height":240,"article:tag":["development","ios","mac","objective-c"],"article:published_time":"2013-03-20T14:37:14+00:00","article:modified_time":"2021-06-07T13:45:24+00:00","twitter:card":"summary_large_image","twitter:site":"@ecpplus","twitter:title":"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","twitter:description":"magicalpanda\/MagicalRecord CoreData \u306e ORM\u3067\u3042\u308b MagicalRec","twitter:creator":"@ecpplus","twitter:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg"},"aioseo_meta_data":{"post_id":"1422","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-02 12:51:00","updated":"2022-09-29 12:36:50","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\/category\/development\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/ecpplus.net\/weblog"},{"label":"Development","link":"https:\/\/ecpplus.net\/weblog\/category\/development\/"},{"label":"CoreData \u306e O\/R\u30de\u30c3\u30d1\u30fc MagicalRecord \u3092\u4f7f\u3046","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\/"}],"_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}]}}