views:

227

answers:

2

I've been working on and off with a team that's developing an iPhone app. Like a lot of other developers new to Cocoa Touch, we decided to create a hybrid Cocoa-Web app which was essentially a few buttons controlling some UIWebViews -- partly to (a) leverage existing web development expertise, partly because of (b) the advantage in pushing out changes (change stuff on the server, no need to push out a new version of the app), and partly because (c) the app is inherently focused on pulling data from the network anyway.

We've reached a point, however, where this hybrid approach looks like it's having notable costs against polish and performance. We're working on this problem, but I think we've all started to wonder if a more purely Cocoa client might not be a better move.

The big question is -- is there an arrangement under Cocoa where we can keep advantage (b)? Is there some way to serialize Cocoa Touch UI objects in such a way that they can be transmitted over the network and reconstituted for display on a client? If so, when serialized, are they lightweight enough for this to be practical?

+1  A: 

Interesting idea. You can serialize anything that implements the NSCoding protocol—that's what it's for—so pretty much anything you can put into a XIB should allow you to archive it. You might even be able to take advantage of UIViewController's initWithNibName:bundle:; your app could download and expand a bundle containing a nib into its documents directory, then load that with the UIViewController method and NSBundle +bundleWithPath:. I think you might even be okay with the SDK's terms—they forbid loading "plugin" code, but XIBs don't contain anything executable.

For more information, check out the Archives and Serializations Programming Guide.

Noah Witherspoon
+1  A: 

an .xib file is a serialized representation of Objective-C objects. You can archive and unarchive objects the same way that IB does. See the docs for NSKeyedArchiver and related subjects.

NSResponder