GHUnit is quite useful for running and reporting tests (unit or otherwise) for iOS projects, and I’ve been using it for a while with good results. Recently, however, I found as I wrote more and more integration-style tests with a remote HTTP service I found the code getting to be a pain to write and maintain. There were two reasons for this:

GHAssert variants fail with an Exception, and therefore other tests do not continue to execute.

This was a real drag, since the assert macros are pretty handy, but I want all my tests to run, even if some fail (gasp I know!).

So, I ended up replacing the GHAsserts with a simple conditional, which doesn’t feel as clean, but navigates around the issue.

Selector names became copy and paste heavy.

Since I’m making notification calls like [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testAsynchronousOperation)]; from within the same method it was additional grunt work to copy the selector name to all the places I needed a reference to the selector.

I thought of adding a SEL mySelector = @selector(foo); to each method, which would cut down on the copy & pasting, but that just didn’t seem clean to me.

I discovered there is an Objective C variable like self called _cmd* which is a reference to the current selector(!). That’s cool, and simplifies code like my testing code a lot.

Sample

For the specific kinds of test cases I was writing, here’s an example which shows both of these issues resolved:

Since my last post on learning iOS I’ve been asked about the Continuous section and what resources/people/blogs etc. I recommend following.

To be clear, there’s no way to even scratch the surface for all the really great people in this community who should be paid attention to (I continuously find new great people and welcome introductions too!), so please don’t take this as a comprehensive list, but just a place to start… Also, it’s a good idea to keep up on Apple related news, but that’s a different beastie altogether.

Blogs (in no particular order)

Tweeters (in no particular order)

I’ve recently been asked a couple times about resources for developers who want to get into iOS development. I don’t pretend to be an expert, and am constantly learning myself, but these resources are ones I find useful, believe would be good for people just starting, and should certainly get you started. There’s lots of information out there, so don’t get too overwhelmed.

The First Place

I’d start is with a good book. Aaron Hillegass is the goto guy for learning Cocoa and Objective C.

Second, Apple’s documentation is quite good and will be your constant companion. Use the Documentation tab of the Xcode Organizer to search and browse the docs. There are many many sample code projects on various topics.

The docs are also online… some good starting places are:

View Controllers are the “main entry point” when using UIKit. It is important to understand them… many iOS devs do not (I was making fatal mistakes for my first year!). Read Apple’s View Controller Programming Guide until it makes sense. Paying particular heed to the view hierarchy and view controller hierarchy concepts.

Attend a Conference/Course

If you’re at all like me, you’ll most likely come away inspired and energized to build cool stuff. I’ve been to two 360iDev’s now and loved them both. Highly recommend.

The Pragmatic Studio just announced a session which looks promising.

Continuous

Follow people on Twitter who talk about iOS and Cocoa. There’s a lot of people out there with a lot of experience.

This should lead you to some great blog posts and open source projects which will help you learn and grow, as they continue to do for me.

Check out Ray Wenderlinch’s site for some great intro to intermediate tutorials to get you going.

A great place to go for answers is StackOverflow. Search before you post… it’s probably been asked (and answered) already.

Lots to know

There is a difference between intelligence and knowledge. Do not sell yourself short.

Give Back

Probably about the most astounding thing I encountered when I first joined this community, for that is what it is, was the unselfish and unpretentious giving of knowledge and experience. There is an amazing amount of source code out there, for free. People are writing blogs and answering questions all the time. When you have the experience, pay it forward and help the community by sharing.

Sounds pretty basic, and it is, but like many things there are lots of ways to do it. This is my new favorite:

1
u_int32_t arc4random_uniform(u_int32_t /*upper_bound*/) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);

Based on discussions on StackOverflow and my own testing.

This assumes you’re on iOS 4.3 or later, however.

Start:

1
2
3
sudo dscl . -create /Users/ftp
sudo dscl . -create /Users/ftp NFSHomeDirectory /Users/labrown/Public/ftp
sudo launchctl load -w /System/Library/LaunchDaemons/ftp.plist

Stop:

1
2
sudo launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
sudo dscl . -delete /Users/ftp