Part of the online course that I took from Stanford on iPhone app development involved choosing a final project. My top-level criteria for choosing a project included:
- Incorporate several different iOS technologies.
- Make use of an external web service and API.
- Interaction with an external web site.
What I eventually settled on was a concept for allowing a user to view and edit their iPhone Address Book contacts both within an app as well as in a full web browser.
This functionality is already available as a service now at iCloud.com. My plan was to start with this capability and over time begin to add new functionality (social sharing, etc).
The Contacts2Web app is now available in the App Store. In this document, I will cover some of the details that went into developing the app.
Posted in iOS
Tagged address book, code coverage, core data, core foundation, debugging, google analytics, instruments, iOS, leak, memory allocations, parse, singleton
I recently posted an article called Setting up and using Code Coverage. As I mentioned there, code coverage is useful for seeing what portions of your code have been exercised. What code coverage can’t do though is to ensure functional correctness – this is where functional coverage comes into play. Functional coverage allows you to determine when you have exposed your code to a sufficient enough set of stimulus, including hitting corner cases, that you have a high confidence in its functionality.
My background includes experience as a hardware verification engineer, where the teams I was part of used both code coverage and functional coverage as essential tools in test development. In the Wikipedia section on SystemVerilog (a hardware description and verification language) there is a nice write-up on Coverage where the difference between code coverage and functional coverage is discussed.
What is a Coverpoint?
I wanted to employ some functional coverage as a guide to my unit test development. In the SystemVerilog language mentioned above, they have the concept of coverpoints and covergroups (group of coverpoints). I found a nice document called SystemVerilog Testbench Automation Tutorial where there is some good information about these concepts starting in the section titled “Functional Coverage”.
A coverpoint is essentially a measurement point where an event (such as values taken on by a variable) can be recorded, along with bins for how many times specific values (or range of values) occurred for that event.
I have an application that I’m working on that uses Parse (a service that lets you persist objects in the cloud, perform queries, etc.). Calls to the Parse APIs are initiated from the main thread and dispatched to the global queue, thus completion of these calls happens asynchronously.
I wanted to write some unit tests to verify the functionality of my methods that interface with Parse.
Referencing the View Controller
My initial view controller is called EntryViewController. This view controller instances a class called ParseConnection which serves as a model for all my Parse interactions. All calls to methods in ParseConnection from EntryViewController are dispatched to the global queue. Within ParseConnection, all the API calls are made synchronously in this background queue.
My first challenge was how to get a reference from my unit tests to EntryViewController. I wanted to do this from the instance setUp method in my test suite class called ContactsOnlineBasicUnitTests, and store this reference in a property. This setUp method is called before each test case is run.
@interface ContactsOnlineBasicUnitTests ()
@property (strong, nonatomic) EntryViewController *entryViewController;
I’ve been making more use of threads and recently needed to allow two threads (neither of them the main thread) to coordinate with each other. In this particular case I was logging into Parse in one thread and moving some data from the Address Book to Core Data in the other thread. Once both threads completed, I wanted to call a routine that would allow me to communicate with Parse and update some records in the cloud as needed.
As an aside, I wanted to put in a quick plug for Parse. It’s a great service that allows me to persist objects in the cloud, perform queries, etc. The documentation is great and the team has been very responsive on their forums. I hope to write about my experience with Parse more extensively in the future.
Conceptually, it isn’t difficult to think about how to synchronize the completion of the threads before kicking off my update method. I just need to keep a flag somewhere that both threads can check.
@property (nonatomic) BOOL readyForParseUpdate;