Don't miss Joystiq's up-to-the-minute live coverage of E3!

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.

Related Headlines

Reader Comments (Page 1 of 1)

TUAW Features

iphone app store tuaw tests
Mac 101 ask-tuaw
Mac News
WWDC (251)
.Mac (65)
Accessories (641)
Airport (75)
Analysis / Opinion (1368)
Apple (1671)
Apple Corporate (566)
Apple Financial (193)
Apple History (48)
Apple Professional (54)
Apple TV (164)
Audio (447)
Bad Apple (121)
Beta Beat (152)
Blogging (86)
Bluetooth (17)
Bugs/Recalls (56)
Cult of Mac (873)
Deals (219)
Desktops (115)
Developer (265)
Education (100)
eMac (10)
Enterprise (140)
Features (406)
Freeware (386)
Gaming (377)
Graphic Design (33)
Hardware (1287)
Holidays (37)
Humor (579)
iBook (65)
iLife (237)
iMac (184)
Internet (334)
Internet Tools (1325)
iTS (977)
iTunes (814)
iWork (22)
Leopard (370)
Mac mini (112)
Mac Pro (53)
MacBook (202)
MacBook Air (79)
Macbook Pro (220)
MobileMe (41)
Multimedia (445)
Odds and ends (1452)
Open Source (280)
OS (919)
Peripherals (210)
Podcasting (182)
Podcasts (91)
Portables (197)
PowerBook (135)
PowerMac G5 (50)
Retail (600)
Retro Mac (48)
Rig of the Week (42)
Rumors (633)
Software (4359)
Software Update (419)
Steve Jobs (252)
Stocking Stuffers (50)
Surveys and Polls (97)
Switchers (113)
The Woz (34)
TUAW Business (243)
Universal Binary (281)
UNIX / BSD (61)
Video (905)
Weekend Review (84)
WIN Business (47)
Wireless (85)
Xserve (39)
iPhone/iPod News
iPhone (1648)
iPod Family (2073)
App Store (96)
SDK (24)
Mac Events
One More Thing (27)
Liveblog (2)
Other Events (226)
Macworld (489)
Mac Learning
AppleScript (3)
Ask TUAW (104)
Blogs (85)
Books (26)
Books and Blogs (62)
Cool tools (446)
Hacks (466)
How-tos (487)
Interviews (44)
Mods (188)
Productivity (590)
Reviews (112)
Security (156)
Terminal Tips (59)
Tips and tricks (568)
Troubleshooting (169)
TUAW Features
iPhone 101 (34)
TUAW Labs (4)
Blast From the Past (17)
TUAW Tips (144)
Flickr Find (37)
Found Footage (86)
Mac 101 (97)
TUAW Interview (31)
Widget Watch (198)
The Daily Best (1)
TUAW Faceoff (5)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

The Unofficial Apple Weblog (TUAW) bloggers (30 days)

#BloggerPostsCmts
1Cory Bohon794
2Dave Caolo550
3Robert Palmer5339
4Scott McNulty492
5Steven Sande4520
6Mat Lu3811
7Erica Sadun352
8Mike Schramm211
9Giles Turnbull160
10Christina Warren1325
11Brett Terpstra121
12Michael Rose915
13Chris Ullrich30
14Joshua Ellis23
15Kent Pribbernow10
16Jason Clarke10
17TUAW Blogger10

Featured Galleries

Macworld 2008 Keynote
Macworld 2008 Build-up
Apple Vanity Plates
DiscPainter
Crash Bandicoot Nitro Kart 3D
Macworld Expo 2007 show floor
Apple Texas Hold 'Em
The Macworld Faithful in Line
iPhone First Look

 

    Most Commented On (7 days)

    Recent Comments

    More Apple Analysis

    More from AOL Money and Finance

    Other Weblogs Inc. Network blogs you might be interested in: