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.
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.













Reader Comments (Page 1 of 1)
8-03-2007 @ 6:04PM
Donald Burr said...
Erica, you are amazing. I say that in all seriousness. Way to go! And don't let the farking idiot naysayers get you down.
Reply
8-03-2007 @ 6:08PM
Jon said...
I thought the iPhone SDK hadn't been released yet? Your post confused me.
Reply
8-03-2007 @ 6:18PM
Donald Burr said...
I think she's talking about the SDK that the iPhone hacking community slapped together. Seems as though it has progressed quite nicely.
Reply
8-03-2007 @ 6:26PM
rp said...
I'm impressed by your dedication and tenacity regarding this phone. You basically answer all the questions that I have about any given revelation with it. Please keep up the good work. I don't know why people think it's not important to post a well-written first hand experience of something apple related on an apple specific website. if you don't want to read the article because you don't like the particular product, continue past it. it's really not hard, i do it all the time on engadget. however, since i am interested in the iphone (although i don't own one and won't for quite a while), i like to read about interesting developments. seriously, big up. i imagine that we'll be seeing many more interesting things regarding the SDK in the near future.
Reply
8-03-2007 @ 6:29PM
Michael B. said...
Cool. Can you get it to work when you rotate the phone to landscape? How much further can you go with the SDK?
Reply
8-03-2007 @ 6:58PM
Eli said...
Erica, you never cease to amaze me. Not only are you the best and most interesting blogger on TUAW, you're also an experienced coder. Way to go!
Reply
8-03-2007 @ 7:25PM
Dave Hedgehog said...
Erica, one post I would see is a simple, non-unix geek guide to installing the current toolchain so users like me could install apps like your screenshot program. Any chance you could write a how-to on that?
Reply
8-03-2007 @ 7:37PM
jgjay said...
"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."
This is nothing special. I can do the same with just as few lines with Java and SWING.
I'm all for praising Apple when it's deserved, but the ease of use you are talking about is pretty much DEMANDED of ANY major API or User Interface Toolkit.
That said, it is AWESOME to see 3rd party development happening on the iPhone. I SERIOUSLY hope Apple don't shut it down by the time the iPhone reaches the UK!
Reply
8-03-2007 @ 8:04PM
Anthony said...
@ 8 jjgay - SWING is on the iPhone? No? Then STFU. :P
Erica, stop being modest. We all know what a phenomenal programmer you are!
Reply
8-04-2007 @ 1:22AM
Jon said...
"That said, it is AWESOME to see 3rd party development happening on the iPhone. I SERIOUSLY hope Apple don't shut it down by the time the iPhone reaches the UK!"
I don't see why they would. Killer apps mean more sales of the phone. They'd only want to stop people from hacking stuff they shouldn't, like switching to another operator.
P.S. It's good to see female programmers.
Reply
8-04-2007 @ 5:25AM
Rick said...
Anthony: 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.
Reply
8-04-2007 @ 7:03AM
Tubby Bartles said...
"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.
Reply
8-04-2007 @ 11:44AM
jon freibourn said...
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?
Reply
8-04-2007 @ 12:38PM
JeffDM said...
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.
Reply
8-04-2007 @ 4:46PM
Panamajack said...
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 ?
Reply
8-05-2007 @ 2:09PM
poopie said...
Who 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.
Reply
8-06-2007 @ 1:05PM
cesar said...
Is there any possibility to now hack SMS Text and Notes so you can get the keyboard to work under landscape view?
Reply
8-06-2007 @ 7:19PM
oscar said...
is there any tutorial to install this application?, im not a programer, i would love to have this app on mi iphone thanks
Reply
8-23-2007 @ 5:15PM
ROBBIE said...
i 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
Reply
10-16-2007 @ 10:31AM
tim j said...
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?
Reply