How exciting: I’ve just written a Web Browser for the iPad!

Today you find me rather speechless: because I’m sitting here with my iPad which is running a web browser that I’ve just written in Xcode!

As in “written myself, working and doing what I’m expecting it to do”. I’m in SHOCK!

This is seriously cool – and it didn’t take long either. Let me tell you how this happened, how it works and even share the code with you.

Inspired by a brief chat with Alexander Clauss who’s famous for creating the iCab Web Browser for iOS and Mac, I’ve been hacking away following the 3rd edition of SAM’S Teach Yourself iOS Application Development by John Ray.

I’ve read the two other editions as well (one for iPhone and one for iPad), and I’ve always been struggling with it a bit. Mainly because they were written for Xcode 3, and by the time I started with Xcode last year Version 4 was out – which was of course completely different.

This time round I’m reading it and can actually UNDERSTAND what’s happening – so rather than blindly typing code that I don’t get, I’m reading the chapter and then try to re-build exercises from memory. Which works most of the time.

One of the “Further Exploration” exercises was: build a mini web browser, with bookmark buttons and a URL bar. I did this – and here’s my result:

Here's my web browser - I've made Julia a version with orange background 😉

All it is really is a UIWebView to display he website, a UITextField to take in your web address, and a UIButton to kick off the function that sucks in the URL. I’m amazed what those few lines of code can do.

The Bookmark Buttons call the surfWebsite function with pre-defined URLs. For the first time since starting this complicated journey in July 2011 I can say I’m beginning to like Xcode and Objective-C a little bit.

Here’s the code – written with Xcode 4.3.2. If you find it useful, be my guest and enjoy it:

I can’t wait to get my hands dirty with the next project, and making this one rotation aware, universal and maybe finding out how to best create a “back” button.

Usually I get extremely frustrated because things are just not easy and straightforward with Xcode, and I have to admit that coding seriously does not come easy to me. I’m delighted and in shock at what I’ve done here – and I’m going to go and celebrate this achievement now.

😉





Add your voice