{"id":746,"date":"2013-09-02T14:23:35","date_gmt":"2013-09-02T14:23:35","guid":{"rendered":"http:\/\/triangleappshow.com\/?p=746"},"modified":"2022-12-15T06:46:43","modified_gmt":"2022-12-15T11:46:43","slug":"core-data-and-ios-part-2","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/blog\/core-data-and-ios-part-2\/","title":{"rendered":"Core Data and iOS (Part 2)"},"content":{"rendered":"<p>In the last post, I described how to create the template Core Data App, and showed you a few screenshots. \u00a0In this one I&#8217;ll walk thru the files that are created:<\/p>\n<p>First lest&#8217;s look at the structure of the project. \u00a0We choose a universal app, so we have two storyboards, one for the iPad and one for the iPhone. \u00a0We gave our class prefix of TAS (for TriangleAppShow) so our basic AppDelegate is created (both header and object source) as TASAppDelegate. \u00a0Our master and detail views are named TASMasterViewController and TASDetailViewController respectively. \u00a0I&#8217;ve expanded the other subfolders, but won&#8217;t go into those files, other than to note that the CoreData.framework is included in your Frameworks folder. \u00a0The file we will focus on first is the Data Model &#8211; CoreDataProject.xcdatamodeld.<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.57.50-AM.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-747 aligncenter\" alt=\"Files Created\" src=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.57.50-AM.jpg?resize=534%2C944&#038;ssl=1\" width=\"534\" height=\"944\" \/><\/a><\/p>\n<p style=\"text-align: left;\">\n<p style=\"text-align: left;\">Once you select that file, you should see the following screen:<a href=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.58.19-AM.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" wp-image-748 aligncenter\" alt=\"Visual Data Model\" src=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.58.19-AM-1024x687.jpg?resize=660%2C442&#038;ssl=1\" width=\"660\" height=\"442\" \/><\/a><\/p>\n<p style=\"text-align: left;\">\n<p style=\"text-align: left;\">If, you don&#8217;t see the above screen, click on the following symbol:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-10.09.37-AM.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-750 aligncenter\" alt=\"EditorView\" src=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-10.09.37-AM.jpg?resize=400%2C146&#038;ssl=1\" width=\"400\" height=\"146\" \/><\/a><\/p>\n<p style=\"text-align: left;\">\u00a0at the bottom right of the main view to switch to this view.<\/p>\n<p style=\"text-align: left;\">This view allows you to model the database and it&#8217;s relationships. \u00a0The Entity Relationship model describes the <strong>Entities,\u00a0<\/strong><strong>Events, Attributes, and Relationships<\/strong> that make up your data model. \u00a0The way I like to think of this is as follows:<\/p>\n<p style=\"text-align: left;\">Entities are tables that store the varies events (rows). \u00a0Events are made up of Attributes (columns). Events are tied together via Relationships. \u00a0Relationships are either one to one or one to many. \u00a0The sample project has only one event , with one attribute and no relationships. \u00a0You will create a new event every time you select the + button in the app. \u00a0That event will store a single attribute &#8211; the timestamp itself.<\/p>\n<p style=\"text-align: left;\">The next screenshot shows you the simple definition of the event:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.58.34-AM.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-749 aligncenter\" alt=\"Entity Description\" src=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-9.58.34-AM.jpg?resize=552%2C894&#038;ssl=1\" width=\"552\" height=\"894\" \/><\/a>The name is Event &#8211; this is how we will reference it in the code of the app. \u00a0It does not yet have a class (more on this later). \u00a0Since there are not relationships, we have no Parent Entity. \u00a0We also have no indexes &#8211; this are used to optimize search via predefined and maintained sorts.<\/p>\n<p style=\"text-align: left;\">If you select that attribute timeStamp the right panel will show you its definition.<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-10.20.14-AM.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-751 aligncenter\" alt=\"Timestamp Attribute\" src=\"https:\/\/i0.wp.com\/rowewp.mydrobo.com\/wp-content\/uploads\/2013\/09\/Screen-Shot-2013-09-02-at-10.20.14-AM.jpg?resize=524%2C450&#038;ssl=1\" width=\"524\" height=\"450\" \/><\/a>We see that this field is optional, with a name of timeStamp. \u00a0It is currently not indexed, so we assume that events are store in order that they are created. \u00a0The Attribute type is Date, with no other validations.<\/p>\n<p style=\"text-align: left;\">So far, pretty simple. \u00a0In the next post I will look at how the app actually creates each event.<\/p>\n<p style=\"text-align: center;\">\n<p style=\"text-align: center;\">\n","protected":false},"excerpt":{"rendered":"<p>In the last post, I described how to create the template Core Data App, and showed you a few screenshots. \u00a0In this one I&#8217;ll walk thru the files that are created: First lest&#8217;s look at the structure of the project. \u00a0We choose a universal app, so we have two storyboards, one for the iPad and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_wp_convertkit_post_meta":{"form":"-1","landing_page":"0","tag":"0","restrict_content":"0"},"hide_page_title":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[2],"tags":[],"class_list":["post-746","post","type-post","status-publish","format-standard","hentry","category-blog"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2aMa8-c2","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":1,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":2862,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/746\/revisions\/2862"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}