Journeys inside the iPhone's SDK
I have now spent a pretty solid week writing applications for the iPhone. And what an exciting week it's been. I've been privileged to view and interact with the iPhone in a way that few other people have had the opportunity to. The iPhone is tight, robust and its SDK--even seen through such imperfect tools as class-dump--is beautiful.
Let me give you an example. This morning I decided to write a basic word processor for the iPhone. In about 30 lines of code, I was able to create an application that saved all changes to disk and reloaded that text launching the application. That kind of success doesn't happen because I'm some sort of phenomenal programmer, it happens because Apple makes amazing, usable libraries. I was able to use classic Cocoa strategies like reading a string to and from disk and combine it with new UIKit strategies like creating a keyboard that automatically knows how to enter and edit text.
The hardest part of the process was figuring out how to know when the iPhone Application was about to quit. I fumbled around for a while trying to use standard Cocoa delegates, like "applicationShouldTerminate". In fact, I should have gone straight to the UIApplication include file instead of trying to "Think Cocoa". The correct delegate was applicationWillSuspend. This reorientation of the discovery process is important. The iPhone is not a Macintosh. Its vocabulary, libraries and frameworks reflect that difference.
I've put all the source code for the TextEdit app up over at Textmate.org. If you're interested in looking through the code, here's the Makefile, mainapp.m, SampleApp.h, and SampleApp.m. Or you can find all four on our iPhone hacks page.
As you can see, the application basically sets up a UIWindow, allocates it and establishes its bounds. It then adds a main UIView and to that view adds two subviews: the text and the keyboard.
I added persistence (the way the application remembers its text from one time to the next) with two lines, both provided by NSString. The first writes the string to a file, the other creates a string with the contents of that file. That's a pretty awesome amount of power for two lines of code and again shows why Apple rocks.
Share
Source: http://pastie.textmate.org/84719
Categories
I have now spent a pretty solid week writing applications for the iPhone. And what an exciting week it's been. I've been privileged to...
Add a Comment
hey programmer guys - I'd like to buy a good iphone text editor for email and sms that T9s words and operates in landscape mode (bigger buttons)... do you guys know where i can find one?
October 16 2007 at 10:28 AM Report abuse Permalink rate up rate down Replyi have a problem...when i press save it goes back to the springboard....if i hit open nothing happens...and also if i use the magnifier to replace the spot to type nothing happens, the glass piece pops up but thats all....please help thank you
August 22 2007 at 5:05 PM Report abuse Permalink rate up rate down Replyis there any tutorial to install this application?, im not a programer, i would love to have this app on mi iphone thanks
August 06 2007 at 7:16 PM Report abuse Permalink rate up rate down ReplyIs there any possibility to now hack SMS Text and Notes so you can get the keyboard to work under landscape view?
August 06 2007 at 12:52 PM Report abuse Permalink rate up rate down ReplyWho gives a damn. Write us a bathroom-safe, wifi-free, network-disconnected game we can play while dumping out!
Damn if our johns are free of signal.
Fantastic stuff Erica!
As much as I hope Apple offically releases the iPhone API and makes some slickity slick SDK for all you brillant code monkeys to play with, I could also see Apple just picking off people like Erica and keep programming for the iPhone internal.
It sucks being in that 5-10 % of the market who really needs Palm OS / WCE (arrgh!) 3rd apps ported in some (hopefully Cocoa-licious) fashion to the iPhone before I'd consider buying one (at least at the current price point).
All good things come to those who wait ?
That looks pretty interesting. What's the license? Technically, it's copyright Erica Sadun, even if there's no copyright notice. Would a person be correct in presuming that Erica had made it public domain?
I guess it really doesn't matter that much to me, I really don't understand the code, I need to get into a good beginner Obj-C and Cocoa book.
Bless those Java guys, they're always the first to step up and talk about how Java does it better. Meanwhile the rest of us are sick to death of trying to use Java-based applications. Maybe you could do the same thing in Java, but would anyone want to use it?
August 04 2007 at 11:12 AM Report abuse Permalink rate up rate down Reply"I can do with a few lines of JAVA and Swing". Good lord, jgjay. Having written apps for phones before, I can say Erica's right - this is amazing. It was one of the most painful experiences to go through; the tools and libraries for most phones are where unix was when I was coding apps for that in 1990. 30 lines of code for a text editor is *amazing* for a phone; when Apple opens the SDK (or this group does it for them) some of these apps are going to be amazing.
August 04 2007 at 7:03 AM Report abuse Permalink rate up rate down ReplyAnthony: what a piece of crap of a comment.
jgjay (not jjgay) was obviously referring to the "30 lines for GUI app" part of the article and really mentioning SWING was just to prove his point that it's quite normal for GUI libs to be that easy.
So stop putting things out of context and, YOU STFU.
Hot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



20 Comments