Tag Archives: beginner

One Method to Learn How to Build an App Using Core Data in Xcode

I am new to this programming gig. I have always been interested in technology, but mostly as a user.

I began coding with Objective C programming language in March 2013, and even then only really began daily work as a beginner programmer the following May. I use Apple’s free Xcode to develop apps for iOS. I hope to develop apps for OS X in the near future.

This blog is not intended as a definitive guide. This blog is intended to assist people who, like me, are interested in developing an iOS app that incorporates a scalable and easy to use database managed by Core Data, and who also like me had NO IDEA what to do when they entered the world of software programming and in particular programming for iOS and OS X using Xcode.

There are literally thousands of online written and video resources, available at blogging and Q&A internet sites such as WordPress, YouTube, iPhone Dev SDK, Techtopia, Stack(ego)overflow etc… (the list really does go on and on and on and on). You will most likely end up using a few of these.

Many internet sites are Q&A format – dedicated to allowing their users to present questions which are then answered by the wider user community. Be careful using these – they are not ‘user-friendly’ for beginner programmers. It seems many experienced programmers are pedantic to a point that suits them, and some suffer very fragile egos. Often a well meaning and carefully worded question is interpreted as a personal attack on credibility. Generally I find that most questions have already been asked – so search the existing questions and answers. If you intend to make a comment, keep these comments in mind, and wait until you REALLY DO UNDERSTAND what you are attempting to comment on.

So – what is Core Data and why use it?

Don’t take my word for it – read the description by Apple – as of writing this, the following online document was a good starting point – https://developer.apple.com/library/ios/referencelibrary/GettingStarted/GettingStartedWithCoreData/index.html#//apple_ref/doc/uid/TP40005316

From my simplistic point of view, Core Data is a great iOS framework that makes it easy to prepare and manage a persistent (data) store (i.e. a database or other persistent file).

Persistence in computer science terms is described by Wikipedia as follows: http://en.wikipedia.org/wiki/Persistence_(computer_science)

There exist many so-called drop-in classes/frameworks that attempt to manage Core Data on the basis that they make the process of using Core Data easier. IGNORE THESE. A well developed model and well written code will make Core Data EXTREMELY easy to use, so I would recommend learning how to code efficiently using Core Data. Also worth noting – Core Data already works and is highly optimised, so why learn two languages and confuse the matter!

After my experiences of the last few months, what advice would I have for other noobs? (http://en.wikipedia.org/wiki/Newbie)

In this order >

1. Subscribe to and consume as fast as humanly possible relevant iTunesU courses.

The Stanford University course on app development is extraordinary. As of typing this, the latest course is run by lecturer Paul Hegarty, and is available from iTunesU under the title ‘Coding Together: Developing Apps for iPhone and iPad (Winter 2013)’ which is of course a northern hemisphere winter. Apart from his extremely well prepared curriculum, compelling presentation and extensive knowledge, Paul’s vast array of neatly ironed shirts will amaze you. Unlike me, be smart, plan ahead, and you will be able to do the next course as it is run, and socialise with other external students using the Stanford University ‘Piazza’ service. ( https://itunes.apple.com/au/course/coding-together-developing/id593208016)

2. Read.

This book really deserves its own number!

    • From The Pragmatic Bookshelf – Core Data, 2nd Edition, Data Storage and Management for iOS, OS X, and iCloud (Jan 2013) by Marcus S. Zarra. Read it. Then read it again, and again, and again.

I highly recommend the following texts…

      • From the Apple ‘iOS Developer Library’ the document ‘Getting Started with Core Data’. This document will then guide you to the appropriate references depending on your skill level and whether you are developing for iOS or OS X. (The address is provided above.)
      • From Apress publishers – Beginning Objective-C (2012) by James Dovey and Ash Furrow. A solid text for beginners.
      • From Apress publishers – ‘Beginning iOS 6 Development – Exploring the iOS SDK’ (1st Ed.), by David Mark, Jack Nutting, Jeff LeMarche, Fredrik Olsson. Do the tutorials – this helps develop an understanding of Objective C and Xcode immensely.
      • From Apress publishers – ‘Pro Core Data for iOS (2nd Ed.), by Michael Privat and Robert Warner. This book is written for iOS 5, which makes it almost ancient in computing terms, however it remains surprisingly relevant, as it is a solid way to learn how to prepare an NSPersistentStore, NSPersistentStoreCoordinator and NSManagedObjectContext from an NSManagedObjectModel.
      • From Addison Wesley publishers – The Core iOS 6 Developer’s Cookbook (4th Ed.), by Erica Sadun. Erica presents information in a unique way and, once you get used to how she presents her code in GitHub, provides excellent tools to build you code.

3. Learn to use Github.

What is GitHub you ask? You need to know, so go visit them at https://github.com, sign up and begin learning how to use this tool. Erica places her sample code for the book noted above in GitHub.

4. Build an iOS app using Xcode.

Of course if you are attempting to build an app, this will help enormously as you will be constantly seeking out the next critical piece of information so that you can build the next critical piece of code for your app. There is nothing quite like experience and a NEED TO KNOW HOW to do what is necessary to make your app work.

5. Understand how Core Data fits into the Model-View-Controller Paradigm

Many texts include illustrations and diagrams that attempt to describe Core Data and how it fits into the model view controller paradigm. In my humble experience, most of these help the person that prepared the illustration or diagram a lot more than any of the subsequent readers. So – and this is important – attempt to draw your own diagram. Then be prepared to change it as your understanding develops. In my experience, little will cement your understanding better.

6. Wikipedia

Do not overlook this excellent resource. It can help “click everything into place”.

7. Understand the ever changing world of Xcode IDE and Objective C APIs.

IDE? Integrated Development Environment. http://en.wikipedia.org/wiki/Integrated_development_environment

API? Application Programming Interface. http://en.wikipedia.org/wiki/API

So many times I read an acronym and wonder… HUH? Have a wikipedia tab open in your internet browser so you can search for assistance!

The worlds of Xcode and Objective C APIs are ever changing. As of writing this, iOS 7 is just a couple of weeks off public release. Many and by many I mean most solutions provided on the internet and in books rely on methods and method templates that have already become outdated. YOU MUST understand this – as a complete noob I was often very confused and at cross purposes attempting to create new code in a new IDE, but based on old examples.

Paul Hegarty’s lectures provide an indication on what is current ‘best practice’.

As an example, if you read the books I have recommended, most will present code on the basis that you are building views (what is seen on your device screen) in code. Even books written for iOS 6. Apple has developed the graphical Storyboards feature in Xcode to mostly supersede the requirement to build a view in code. Coding snippets/solutions written for iOS 6 often present outdated code based on an assumption that views will also be built in code. So then interpretation becomes a large part of your research, as you have to take from each solution the actual methods and method calls that you require to achieve an certain outcome in your app, while excluding the parts of the code that relate to creating a view in code. Learn to differentiate – and definitely use storyboards – it is so much easier!

So, where to from here

Now that I have a few months under my belt, the question that is sitting foremost in my mind regarding Core Data usage is this…

There are two methods to prepare a Core Data “Stack” as far as I understand.

a) Use the Apple paradigm that is inserted into an Xcode project when you select the ‘Use Core Data’ option available in a couple of the Xcode project templates. This is as taught by many, including Michael and Robert in their book mentioned above.

b) Use NSDocument as taught by Paul in his lectures.

I do not understand the difference. I began my app which it is now dependent on the first method.

I will however be implementing many of the concepts that Paul teaches in his lectures, so do I reverse out completely and change to NSDocument? That is the big question for me, and as I learn more about Core Data and NSDocument, I will hopefully have time to post my observations here.

Hope this has been of some assistance.

Enjoy your code!

PS – if I am mistaken, please let me know, and I will review and where necessary update my blog. I am always happy to learn from my mistakes.