Using WebView in XCode 4.0 with Objective-C

If you are wanting to use the WebView in your XCode/Obj-C project and are a little underwhelmed and confused by Apple’s docs, as i initially was then here i can show you step by step how to get up and running very quickly and very easily.

Firstly, before we begin this little tutorial is from what i have worked out myself, i found the documentation a bit confusing myself, it tends to ramble on a lot and not give the reader much in the way of code examples as i will do here; namely it talks more about Carbon than Cocoa front ends and the example code is very obscure and out of context and fails to mention several key steps for newcomers to Cocoa/Obj-C. The following steps are what i gathered from the documentation plus a little googling.

Chances are, if your reading this then like myself¬†you got an error when trying to run you app after placement of the WebView and further more if you get past compilation you get a runtime error of:¬†“program received signal: SIGABRT” in the code as a sort of fix-it tab and a GDB output of: “Terminating app due to uncaught exception ‘NSInvalidUnarchiveOperationException’, reason: ‘*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)”.

The 2 most significant steps that the apple docs don’t mention are 1) stating the header file for Webkit, which if your used to working in Windows you would not import the rendering engine for a webview equivalent and may be thrown by that and further more 2) import the webkit framework into the project.

So heres the steps you should take:

1) Create your project, here i created a basic cocoa project called webber.

2) Add the WebKit.framework to your project as shown below:

On the project configuration page click the plus under the "Linked Framework and Libraries" list as shown in the figure above.

search for webkit and select the webkit framework.

The linked frameworks and libraries should look like the figure shown above.

3) Add the webView to your window, in this instance i also added a textbox and a go button:

Add your webView to your project.

4) Drag your IBOutlet connections to your AppDelegate, you will need an outlet for the navigation textbox (navbar) and one for the webView component (webber), and lastly a IBAction for the go button (go). Then at the top of the code add a header for webkit, #import <Webkit/Webkit.h>. You should have something resembling this:

Establish your IBOutlets and IBActions as shown above and add the Webkit header.

5) Now we add the implementation code to your AppDelegate.m file in the go and applicationDidFinishLaunching method:

Add the implementation code.

So the first applicationDidFinishLaunching method will set the homepage of your webView to the apple site initially and after that you can type in a url in the textbox and click go and the browser will take you to the requested site.

Simples! I hope this helped those of you who bothered to read. Good luck and have fun with it.


HP Pavilion dv6-3119sa Entertainment Notebook PC (XU644EA) Review

New laptop! YAY. So i decided i wanted a new machine to run linux on as its a bit tiresome running Linux in a VM, and on my Macbook Pro the EFI is often problematic for linux installs; that said there are work arounds but i preferred to avoid that grief and go for the simpler option. So i bought a new laptop for my Linux installs so i could take it out and share what i am working on with friends with anything *nix related.

I had planned in the future to learn a bit about hypervisors and how to effectively run and manage linux machines on a hypervisor and this is great for that. Now i can take it out and work with friends in person with it.

So for the review; i had looked around pretty hard to find a decent laptop that wouldn’t break the bank but that also had good hardware and a design that does not compromise. Which incidently is very difficult to find. Most laptops out there in my humble opinion are just ugly; though for those of us who prefer something with a bit more taste the HP Pavilion DV6-4119SA is a beautiful machine. If your a fan of Mac’s; much like myself, then you will love this machine for running Windows. The typical install of Windows it ships with (Windows 7) works great on the Core i5 processor in it, though like most new machines you will need to decrapify it (URL: to make it run at its best.

The streamline shape and slim profile along with its black chick keys and multi touch trackpad this machine is quite reminiscent of the aluminium Macbook’s. Of course this is discounting the fact that the case design is not a unibody design and it comes with a drive trey instead of slot loading optical drive. That said overall its a really nice machine, specially for windows users who desire a better looking machine that delivers results.

Things of note however are that you don’t get a recovery dvd as seems to be customary in so many modern PC manufacturers these days and that for running Linux you may encounter a few hick-ups.

I find the trackpad to be somewhat annoying in Linux distro’s, namely because HP decided to emulate the Macbook to the degree that the trackpad has only one click button under its surface which maps wether you have a right or left click on the basis of which side of the touchpad your finger is pressed on. This is very annoying on the typical Linux desktop environment because Synaptic’s don’t seem to offer any linux drivers or software to support this; or least not that i have found yet and so i am left without a right click option as a result because Linux considers clicking anywhere a left click even on the right hand portion of the trackpad.

Also in my experience thus far i find the Wireless to be sketchy but this may not be the fault of the machine or Linux. To clarify on this Windows 7 runs on Wifi just fine with no problems; setup was quick and pane-less and i was on the web in no time. In Linux however it has been a different story, Linux Mint 10 LXDE and XFCE seem to connect to the wireless router just fine, though Mint 10 KDE and Gnome seem to not want to connect at all and i have tried playing around with the settings but am yet to find the problem, it could be a configuration issue. Xubuntu is also facing similar problems. Kubuntu and Ubuntu are yet to be tested on this issue.

On the plus side however i consider the boot up of most Linux distro’s on this machine to be very fast.

In terms of price, i find ordering directly from HP to offer the best price on this laptop and was not able to find it cheaper elsewhere so i would recommend buying direct. I did do a froogle search and also checked amazon and ebuyer directly but they could not beat HP’s own price.

In conclusion i highly recommend this laptop from my usage of it thus far, it has great design, works well, boots fast and looks great.