Yes it's already done. The Interface Builder which is the standard UI builder in the Cocoa world uses XIB
files, which is an XML file encoding all of the UI. The XIB
file and the program code are very loosely coupled, and XIB
files can be independently changed without requiring re-compiling. It used to be a non-XML files called NIB
s, but the difference is just implementation detail and we shouldn't care.
Objective-C and any language which has a binding to Cocoa knows how to read an XIB
file and instantiate UIs frozen in it.
If you just want to have a dynamic UI decoupled from the code, it has been standard on OS X (and NeXTStep) since time immemorial. In fact, in Cocoa world, it was very rare to set up UI elements by explicitly coding them. Everybody, including Apple itself, uses Interface Builder. The world finally started to catch us up these days:)
One problem might be that the XML schema is a private thing to Apple, but there are already a few utilities available which works on XIB
files. Apple's own ibtool is one example; An open-source project called nib2objc is another. This one dumps the XIB/NIB files into an equivalent Objective-C code, for ye olde timers who can't stand seeing the code to build the UI.
Addendum: I should emphasize again that the fact that XIB file is an XML file is an implementation detail from Apple's point of view, and you're usually not supposed to touch the XML file directly. What Apple wants to achieve is the loose coupling of the logic and the UI, and using XML is just a detail. So, you need to decide whether
- you want to use XML for interoperability, or
- you want to decouple UI from the code.
What you wrote in the question sounded like 2. Then Interface Builder is the perfect match. However, if 1 is what you want, the XIB file won't suit you.