The iOS Dev Diary

The iOS Dev Diary

By Jay VersluisTechnology
Download on the App Store

The iOS Dev Diary episodes

  • How to bind an NSArrayController to an NSTableView

    In this episode I will show you how to bind a Table View to an Array Controller in Cocoa, using Xcode 5.1 and OS X Mavericks.

    We’re using Core Data to save our entries and – check it out – we’re not writing a single line of code!

    Cocoa Bindings is one of the most exciting features in OS X development for me, and I hope that one day it’ll find its way into iOS too.

    The project is also available on GitHub:

    • https://github.com/versluis/Bindings-Demo
    • I’ve written more about how to do this here:

      • http://pinkstone.co.uk/binding-an-nstableview-to-core-data-without-code/
      • Watch the full course in one convenient playlist:
        Catch this episode on my iOS Dev Diary Podcast:

        18 min
      • How to tear down your Core Data Stack

        You may have heard this expression before: “You need to tear down your Core Data stack before you do xyz”. It’s frequently mentioned in the Apple documentation – sadly without telling us what on earth this means or how to do it.

        I had assumed that it means rebuilding every aspect of Core Data, which without a complete app re-launch looks like a daunting task. But it’s relatively easy if you know how to do it. In this article I’ll show you how.

        The secret is in the NSPersistentStoreCoordinator: all we really have to do is remove the store files from it and then add them again. Here’s a method that does just that and more (add it to your AppDelegate.m file to use it):

        - (void)rebuildCoreData {
        [self.managedObjectContext lock];
        [self.managedObjectContext reset];
        NSArray *stores = self.persistentStoreCoordinator.persistentStores;
        for (NSPersistentStore *currentStore in stores) {
        // remove store files
        [self.persistentStoreCoordinator removePersistentStore:currentStore error:nil];
        // delete those store files
        [[NSFileManager defaultManager]removeItemAtURL:currentStore.URL error:nil];
        }
        _managedObjectContext = nil;
        _persistentStoreCoordinator = nil;
        [self managedObjectContext];
        [self.managedObjectContext unlock];
        }

        Let’s go through this line by line: first we’ll lock and reset our managed object context for safe measure. This will make sure no other thread is working with it while we’re meddling.

        Next we’ll iterate through all possible store files in our coordinator. The Core Data template provide only one, but just in case you have more, we’ll remove them all. In this loop we’re also deleting all files from the hard drive.

        Then we set the variables of both coordinator and object context to nil – an ingenious tip from Luke McNeice (Thanks, Luke!) We do this because in the next step we can just call the custom initialiser for self managedObjectContext again which will rebuild the stack.

        Finally we unlock the context so other threads can access it concurrently.

        Demo Project

        Here’s a fully working Demo Project on GitHub which employs this technique. It’s based on the Master/Detail Template and adds an extra button to tear down the stack in a running iOS App:

        • https://github.com/versluis/TearDownTest
        • Further Reading
          • http://stackoverflow.com/questions/3266084/how-to-remove-all-objects-from-core-data/7704671#comment35059415_7704671
          • Watch the full course in one convenient playlist:
            Catch this episode on my iOS Dev Diary Podcast:

            18 min
          • How to use Git Branches in Xcode 5.1

            In this episode I will show you how to use the Git Branch feature in Xcode 5.1.

            Branches are helpful if you’re developing your app. You can isolate a “working” version, create a new branch and fiddle with new features that may destabilise your project. You can then commit your changes – working or not – to a separate branch, and when all is stable again you can merge them back into the master project.

            Watch the full course in one convenient playlist:
            Catch this episode on my iOS Dev Diary Podcast:

            10 min
          • How to use Git Tags in Xcode 5.1

            In this episode I will show you how to make use of Tags in Git. This is not supported in Xcode or GitHub for Mac at the time of this recording (April 2014). I will also show you how to utilise the Tag/Release feature on GitHub.com.

            Tags are a useful feature if you want to mark versions of your software before you add new features. With Tags you can always go back to the code of a release.

            We’re using Xcode 5.1 and the Terminal utility for this. Enjoy!

            Watch the full course in one convenient playlist:
            Catch this episode on my iOS Dev Diary Podcast:

            11 min
          • How to create a searchable UITableView (2014)

            In this course I will show you how to create a searchable table view in Xcode 5.1 and iOS 7. The app will also be compatible with iOS 6.

            There are six parts in total:

            • Part 1: an overview of what we’d like to achieve
            • Part 2: we’ll build the table view and populate it with dummy data
            • Part 3: hooking up the UISearchDisplayController
            • Part 4: displaying search results
            • Part 5: hiding the UISearchBar when the app launches (and activating it with a button)
            • Part 6: hiding the search bar in iOS 6
            • The whole course is about one hour in total. Enjoy!

              Part 1: Overview

              Part 2: Building the UITableView

              Part 3: The UISearchDisplayController

              Part 4: Displaying the Search Results

              Part 5: Hiding the Search Bar in iOS7

              Part 5: Hiding the Search Bar in iOS6 and lower

              Source Code on GitHub

              Check out the full project source code here:

              • https://github.com/versluis/TableSearch2014
              •  

                14 min
              • How to push a local Xcode Project to GitHub.com

                In this episode I will show you how to push an Xcode project to GitHub.com.

                This is useful if you want to share code you have written with others. The GitHub for Mac app makes this a breeze because it talks to GitHub and creates a remote repo on your behalf. It also sets that new repo as a remote in your project.

                Watch the full course in one convenient playlist:
                Catch this episode on my iOS Dev Diary Podcast:

                6 min

              About The iOS Dev Diary

              From the publisher's feed

              Fantastic Adventures in Objective-C