How to Create a Synchronous Wrapper Around an Asynchronous Method

Wrapper Asynchronous methods are the key to keeping your iOS app responsive. Each method running on the main thread has 1/60 of a second to return before it will affect your screen refresh rate. For long-running operations, the typical paradigm is to execute your code on a separate thread (via an abstraction such as dispatch_queue_t or NSOperationQueue), and when it completes, to invoke a completion handler on the main thread. That way the main thread is available to process touch inputs or render UI elements.

Continue reading

How to Get Back the iOS 7 SDK After Upgrading to Xcode 6


iOS 8 finally launched on September 17, and with it, the public release of Xcode 6. However, after upgrading you will notice that you can no longer compile using the iOS 7.1 base SDK. This is a problem for any app that isn’t yet compatible with the iOS 8 SDK. To see what SDK’s you have installed, open the Terminal app on your Mac and enter:

Continue reading

An Overview of Apple’s Swift Programming Language


The jaws of iOS developers everywhere dropped with the announcement at WWDC yesterday that Apple was introducing a new programming language to eventually replace Objective-C, called Swift. The surprise wasn’t that they did it (everyone knew it had to be done), but that it happened so soon. Apple has so much institutional knowledge of Objective-C that to replace it is truly a massive sea change. The problem with Objective-C, being a 25-year old mashup of C and Smalltalk, is that is was never quite fully-baked. And it was not suited for high-performance code, causing developers to revert to C or C++ in many cases. Here are my initial thoughts and observations on how Swift compares to Objective-C and other modern languages. There’s a LOT to cover, so I just picked out the interesting bits:
Continue reading

How to Accept Multiple Enum Values in a Property or Method


Every iOS developer has probably come across a property or method in an API that accepts multiple enum values at once, separated by a vertical pipe. How does that work, and how can we do the same?

Continue reading

How to Add Caching to Cloud Functions in Parse


Parse is a popular backend-as-a-service (BaaS) that essentially gives developers a virtual database and app server in the cloud. You can create a “cloud code endpoint” with a unique name that accepts any number of parameters. This endpoint can then be invoked by the mobile SDK, and a response returned. This response can consist of any number of data objects. For standard database queries, this SDK comes with an additional powerful feature: client-side caching. However, the Parse mobile SDK does not provide caching functionality for cloud functions.

Continue reading

How to Extract the Images From Any App in the App Store


Recently I discovered how incredibly easy it to extract the original, full-resolution images (and other resource files like video, audio, .plist files) from any app in the App Store, without jailbreaking, and without special software. For iOS developers, this can give a fascinating look at the insides of an app. As always, be sure to do this for learning purposes only and respect all apps’ intellectual property.

Continue reading

UINavigationController with Push and Pop Blocks



When creating view controllers programmatically, one of the options is to use a UINavigationController as a container. This allows you to push and pop view controllers on the navigation stack. However, here are some common developer complaints:

  1. You can’t easily capture the ‘pop’ event. That includes ‘back’ button presses. A common solution is to rely on your top view controller’s viewWillDisappear event. However, you still need logic to check whether this event was fired in response to a new controller being pushed instead of it itself being popped.
  2. Showing the navigation bar and toolbar is tricky. This can result in some unexpected animation effects. If setNavigationBarHidden:NO or setToolbarHidden:NO is called too early, the bars will appear before the the controller starts pushing. A solution is to set this in the pushed view controllers’ viewWillAppear event.

Continue reading

SQLClient: A Native Microsoft SQL Server Library for iOS

SQL Server

One of things that surprised me in iOS is the lack of an open-source native library to connect to Microsoft SQL Server.  When googling the topic the usual comments are “why would you do that?” and “just use a web service wrapper.” Well, there are countless business reasons to access a SQL Server on a LAN: POS, data collection, reporting, etc. Further, it’s not always possible or practical to install a web service layer (REST, SOAP, OData) to act as an intermediary. Granted, it is generally much safer to do so, but it does add a layer of complexity (and latency).

Continue reading

How to Automatically Update Xcode Build Numbers from Git

Xcode provides two places to keep track of your app’s revisions: version and build. To see them, click on your Project name in the Navigator, and then click on your main build target under Targets. Click on the General tab. In this post I’ll show you how to automatically update your build numbers with every release build! First, an overview.

Continue reading

How to Generate Beautiful Apple-Style Documentation in Xcode 5

Good code should be self-documenting, but sometimes you also need to generate external documentation for reference purposes. In this post I’ll show you how to use two open-source tools and a build script to create beautiful, Apple-style HTML documentation files in Xcode. I’ll also show you how to create docsets for Xcode so that your class references show up right along side Apple’s! It will be a seamless and dare I say, enjoyable, process for generating documentation.

Continue reading