March 29, 2010

Objective-c Inheritance & Message Passing

Came across an interesting result while overriding a base class last week. Assume we have a class with two methods, one overloading the other as follows.









Assume both methods are defined within the interface (intentionally public). Now when we inherit from this class and override the first method (create:id), where does the "create:int" message in the second method get passed too? It is calling "self" from the context of the parent, but we just overrode the method in the child.





Given the above, where does the message go? Will it call create:id on the child or the parent?

Turns out, it is all in what you declare within your interface for the child. Define




in the child interface and it will pass the message to the child (using your override). Don't and the message will instead go to the parent. Thought it was very curious behavior as a C# guy.

March 6, 2010

Objective-C Libraries and Tools

There are quite a few open source cocoa touch libraries and frameworks.

OCMock, the winner by default when it comes to mocking in objective-c. It is actually a really decent mocking framework with all the elements you would come to expect (mocks, stubs and partial mocks). Setting it up can be a bit of a pain, fortunately Colin Barret has figured that out for us already.

Google Toolbox, augments the SenTestingKit (OCUnit) providing more assertions, log tracking, binding testing and more. A very visual tutorial on setting up Google Toolbox.

GHUnit, I am still spending time with this one. Seems promising so far. Key features are running individual tests, running tests from the command line (easier) and testing macros.

UISpec is a test automation tool. It’s key feature is that it can run automation tests within the simulator (OCUnit must deploy to the iPhone). Documentation is pretty sparse.

ASIHTTPRequest is a library that wraps the CFNetwork API, handling quite a bit of the grunt work for you. Great for working with RESTful services.

json-framework, another key element of working with RESTful services. JSON is lighter weight and uses key-value pairs to represent data. This plays very nicely with the KVC techniques you should be using in Cocoa.

SpeedLimit, this is a great utility for simulating the network speeds you are likely to have on the iPhone.

March 2, 2010

IPhone Development Guide

Just a collection of information and useful advice that I have collected. Hope this helps you get started.

Start where I started doing something simple hello world type examples. All of the icodeblog tutorials are worth doing if you are starting out (though watch out for the SQLite ones as Core Data replaces that now). Try this one to get a feel for interface builder and this one next for tying the code into IB. It can take a little while to learn the name of the different controls you will be using. This tutorial is on one of the navigation controls, the UITabBarController, which visually rests on the bottom of the window and will be one of your staples.

Cocoa has a learning curve of its own, get up to speed on Key-Value Coding (further reading), the framework makes use of many dictionaries. There is also a good post (with even more links) on the MVC Model used on the iPhone. It differs slightly from other representations of the Model View Controller pattern.

Model-View-Controller design patternsource

The primary difference is in the behavior between the different flows back to the view. On the iPhone, only your controller should be interacting with the UIView where as traditionally it is acceptable for the Model to have some interactions (Notifications or checking state).

Matt Gallagher’s blog is probably something that you want to subscribe to. A few of my favorites:

 
Copyright © CodeCuriosity | Theme by BloggerThemes & frostpress | Sponsored by BB Blogging