Core Data and iOS (Part 2)

In the last post, I described how to create the template Core Data App, and showed you a few screenshots.  In this one I’ll walk thru the files that are created:

First lest’s look at the structure of the project.  We choose a universal app, so we have two storyboards, one for the iPad and one for the iPhone.  We gave our class prefix of TAS (for TriangleAppShow) so our basic AppDelegate is created (both header and object source) as TASAppDelegate.  Our master and detail views are named TASMasterViewController and TASDetailViewController respectively.  I’ve expanded the other subfolders, but won’t go into those files, other than to note that the CoreData.framework is included in your Frameworks folder.  The file we will focus on first is the Data Model – CoreDataProject.xcdatamodeld.

Files Created

Once you select that file, you should see the following screen:Visual Data Model

If, you don’t see the above screen, click on the following symbol:

EditorView

 at the bottom right of the main view to switch to this view.

This view allows you to model the database and it’s relationships.  The Entity Relationship model describes the Entities, Events, Attributes, and Relationships that make up your data model.  The way I like to think of this is as follows:

Entities are tables that store the varies events (rows).  Events are made up of Attributes (columns). Events are tied together via Relationships.  Relationships are either one to one or one to many.  The sample project has only one event , with one attribute and no relationships.  You will create a new event every time you select the + button in the app.  That event will store a single attribute – the timestamp itself.

The next screenshot shows you the simple definition of the event:

Entity DescriptionThe name is Event – this is how we will reference it in the code of the app.  It does not yet have a class (more on this later).  Since there are not relationships, we have no Parent Entity.  We also have no indexes – this are used to optimize search via predefined and maintained sorts.

If you select that attribute timeStamp the right panel will show you its definition.

Timestamp AttributeWe see that this field is optional, with a name of timeStamp.  It is currently not indexed, so we assume that events are store in order that they are created.  The Attribute type is Date, with no other validations.

So far, pretty simple.  In the next post I will look at how the app actually creates each event.

Core Data and iOS

I’ve been working on a new app lately, and I’ve taken this time to try and teach myself CoreData.  CoreData is the mechanism by which Apple has taken traditional SQL database and mapped it to the programming model used in iOS apps.  Over the next few blog entries I will try and describe my learning process, in the hope that it will help others pick up CoreData.  Also, I hope to start a dialog to help others, and myself, work thru any challenges which come up during this process.

If you are just starting, I find that Apple’s Core Data template app, is always a good way of understanding how it is all pulled together.  So let’s give that a shot by starting with a MasterDetail Application.  To do this, create a new Project and select Master Detail:

Master Detail

 

After you select that, fill in the next screen.  I have chosen to create a Universal Binary since I think you should always start from there, it exposes you to the ins and outs of MVC (Model View Controller).  Don’t forget to chose CoreData and Automatic Reference Counting.

After choosing the location for the project… give it a compile.  You should have a working CoreData application, that can render on either the iPad or iPhone simulator.

Master Detail Detail Screen

 

As you can see from the following screen shots both the iPad:

iPad Sample Core Data

and the iPhone:

iPhone Core Dataare working fine!

So what do we really have here? We have a simple app that if you click the plus will create a new record (date time stamp) and a detail screen that will show that time stamp.

Detail Screen

That’s pretty much it.

In the next post I will go a bit deeper on all the files that Apple created for you automatically when you chose this template.

Is Your App Ready

If the rumor mill is to be believed, Apple will announce their new iPhone on Sept. 10th. That is not too far away, and as such means developers are working hard to have launch titles available. Realistically, I doubt that Apple will make the iPhone 5s/c or whatever it will be called, ready on the day of announcement; however, I do believe that they will make iOS7 available almost immediately.
As a developer, I am looking forward to releasing updates of my app that will more closely align to Apple’s new UI vision. I am also looking forward to all the new API’s that Apple has been talking about since June’s WWDC.

Android – Root or wait?

For my Android needs, I currently have an Galaxy Tab 2 (10 inch). It is running Android 4.2.1 and I have been wanting to install the latest version of Android, but Samsung has yet to roll the update out for my device. I have read that they are rolling it out around the world, but those reports tend to be a bit confusing. I could root the device and do the update myself, but due to my day job’s policy at IBM this is prohibited on any device that accesses my corporate resources. I currently use the Tab 2 to get my corporate email and instant messaging (using Lotus Traveler and Lotus Sametime for Android). I had these both on my iPhone and iPad, but since, as a developer, I tend to run pre-released and unsupported operating systems I decided to only run corporate software on my Android device.

I guess I could buy another Tab, perhaps the 7 inch, and another iPad (perhaps the mini) and only do upgrades on one device, keeping one device in compliance with corporate policies. What do you think? Do you invest in multiple devices for all of your development environments? One for personal/development use, and one for production use?

Apple finishes update to Developer Portal

Last night, as I was checking my email before going to bed, I got a note from Apple that their replace/rebuild of the Developer portal had been completed and all services are working again.  Great news, and hopefully Apple has addressed, not only the security flaws identified by the Turkish researcher, but any fundamental design flaws which could expose other security issues going forward.

The biggest lessons I’ve learned from watching this all unfold is – security is hard.  Steve Gibson (from Spinrite fame) has been recording a long running podcast on security called “Security Now“.  He spends 2 hours, each week, going thru all the latest info on security patches, and describing the underlying design and technology of various protocols, etc. which shows how much you need to know to make truly secure applications.

Years ago, when I was working as a consultant, I wrote a Human Resources system for a home health care management company.  I was asked to make sure that we had an appropriate level of security and could segregate data between managed companies via passwords.  The design was simple.  Within the application, you had to enter a unique company identifier and password for each company’s data.  Simple and somewhat effective, given that the entire application and all of its data resided on a midrange computer that could only be accessed within the companies physical boundaries.  Within 1 month of the application going live, every monitor within the HR department had a nicely printed sticker listing the company identifier and the password for each.  So much for security.

The reason I bring this up is to identify how technology is only as secure as its weakest link.  Kevin Mitnick, shows us in his biography – Ghost in the Wires, that the best hacks are really around social engineering and not technology.  Even Mat Honan’s famous twitter / gmail / icloud hack, was much more a social engineering issue than a technology flaw.

If you are storing sensitive data (however you define sensitive), what are you doing to make your application secure, with out distracting from its functionality?

iOS7 Adoption amongst Developers

I recently posted a blog entry about upgrading your app, if you should support past versions of iOS or Android. So imagine my delight when I saw this post – Majority of Developers working on iOS7 Updates. A study shows that 52% of iOS developers plan on making their apps require iOS7 and drop support for prior version of iOS. I think this is great. The many new features that are being talked about in IOS7 show that these features are the ones that developers have been waiting for. Features like better multi-tasking and improved screen layout to address multiple screen sizes have all been a long time coming, and I expect that if iOS7 is adopted quickly by consumers, that number of apps that become iOS7 only will quickly go above 70%.

What do you think?

Security and will Monday see another iOS Beta?

Prior to the security issues on Apple’s site over a week ago, Apple had been on a bi-weekly cadence for iOS and OS X beta releases.  Last Monday, (July 22nd) the developer portal was down while Apple rebuilt the site to address the security issues no iOS beta was reported to be released.  With less than 24 hours to go, will they be in a position to release a beta tomorrow?  What is the impact to the overall release schedule of iOS?  What do you think?

I am hoping that the major progress we’ve seen in the last week on bringing the site back online (while still not complete, many of components are up as of this posting), has allowed Apple to focus back on working on iOS and Mavericks.  Perhaps there are some lessons in all of this for us, as developers, that security can’t be something we think about when we are done developing.  Security is something that needs to be built into our apps from the beginning.

One of my favorite podcasts is Security Now! with Steve Gibson of Gibson Research Company. A few months back, Steve talked about the effort he went thru to retrofit his entire website to https.  I think this is something that is worthwhile to consider for this site.  It is a lot of work , and exposed to him the inter-relationship of so much of our connected world.  At an app level, if you use any third party code, are you sure it is secure?  How do you go about testing for security?

The people who want to expose or exploit security issues in your code, spend much more time testing your application than perhaps you do.  They are not worried about shipping the next release.  They are methodical in how they test, probe, and attack your application.  Perhaps this is the time to start re-thinking your development and test strategy, so that security becomes a first class requirement for all that you do.

More Progress on Apple Site

Great news, last night the 2nd major round of site updates were deployed by Apple. Screen Shot 2013-07-27 at 7.30.57 AM

As you can see the site now lets you get to the developer sites for iOS, Mac, and Safari, along with certificates, and software downloads.  Here’s hoping that we are not far from Apple getting back on track for beta updates!