If you have read my blog description just below the blog title you would realize where I am hanging out these days. [object message] is a way to send a message (method) to an object in objective C. I have been working on iphone sdk for a week, going through the online reference library at http://developer.apple.com and stumbling over blogs explaining some code. Let me tell you, this week was full of new learning in terms of a language, a framework and frustrations! Here are a few snapshots of an RSS reader I built for the iphone.
Before I delve into the major discussion about the app, let me frustrate those guys who are just entering the world of iphone development. In the XCode editor, which is used for writiing apps on Mac, there are 2 options to debug an application. One is in the iPhone Simulator whose snapshots are seen above. This is available to everyone who installs the iphone sdk. Other option is directly on the device, iPhone or iTouch. Hold On… You can debug and install apps created on an iphone ONLY IF YOU ARE A REGISTERED IPHONE DEVELOPER PAYING $99 TO APPLE EVERY YEAR. smirks!!! The account used for downloading the sdk is not the one used here. You will notice this when you would try to build the application and install it on your iPhone/iTouch and get an error saying something like Unable to Verify device 0X160434fuc@##$#shi#$#$ :), I learnt the hard way, if you want to know more about this mess read the blog post by Ralf Rottman here.
Anyways, if you are done pulling your hair off, here are some functionalities of the Reader –:
- Add and Remove a feed. The feed data gets stored in a property list which are basically a nice way to store application data.
- A refresh button causes s refresh of all blogs and displays the first post of each of them on the first screen.
- Read the post in a browser window itself. This is done using the UIWebVIew class which allows to open a url in a Safari browser window.
Another word of caution for guys trying to build something which would need to parse XML. The NSXML library which is the one used to parse XML in Mac applications does not work on the iphone/itouch but works on the simulator! I have not personally checked this but there are lots of blogs talking about it. So instead I used TouchXML which is an open source library on http://code.google.com/p/touchcode/. More information about how to use the parser in this library is well explained on Dean’s blog http://dblog.com.au/general/iphone-sdk-tutorial-building-an-advanced-rss-reader-using-touchxml-part-1/. Some good references for beginners are here –:
1) Aaron Hillegas book on Cocoa Programming for MacOSX. – This is an awesome book for guys like me who have been working on Windows platform for a while and want to shift gears for some time and get some Cocoa! The book really helps a lot to make us understand several aspects of the Cocoa framework and Objective C. For ebook lovers, there is an online version of this book somewhere in the cloud, I have it, just search for it.
2) http://developer.apple.com Apple has provided extensive coding how to’s and other references which I found helpful.
3) http://theappleblog.com has good tutorials.
The iPhone sdk uses the MVC pattern, so its a good idea to follow that while building our apps.Create a separate View and View Controller for each different screen you wish to see in your app. If you righr click on the project in the left had side tree view panel of XCode you would see an option to add a Group. Click that and add a UIView and a UIViewController in it. This way you just have a clean separaion of all the files. When you create a project like a Utility Application Project or a Navigation project etc you would see some groups already created. So in short, an iPhone/iTouch app at one time displays a single View added as a subview to the main window. To change the screen, remove the view already there and add a new one. Thats how any application on iPhone/iTouch works.Since I use property lists to store the feed data, it becomes really easy to read and write to them. But do not use these lists if you expect the data to grow too much. Property lists are good for few hundred bytes. They are just XML format files which can be added to a project.
I will be posting some code snippets in my subsequent posts since its the code that matters! By this time in a week time or so I have pretty decent understanding on how the View Controllers, Views and other elements of an iPhone application interact with each other. Ill be talking a bit about using UINavigationControllers, sharing data among views and other important things which are used more often. Please let me know if you have any questions, Ill be glad to help.