XML, the Apple way



  • If you're familiar with development in the Apple ecosystem, you probably know about Plists and their weird XML format.

    If not, click here for a quick explanation. Plists are simply "property list"s which store a list of key-value properties. The value can be a boolean, string, but also a complex type like a dictionary, which itself contains more key-value properties.

    Initially Plists were stored in a text file format somewhat similar to JSON. Then, they've introduced an XML format and a binary format (the latter to optimize loading speed).

    The XML format is something like this:

    <dict>
        <name>value</name>
    </dict>
    

    Nah, I'm kidding. We need to think different!

    <dict>
        <key>name</key>
        <string>value</string>
    </dict>
    

    Yes, one element is the key and the following one is the value. Brilliant.

    Today I was trying to figure out an issue with a storyboard file and I tried to read the XML there...
    Here's an extract of what it looks like (from a random file on github):

    <!--​ stuff -->
                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Don't have a server yet? Choose one of the providers." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uJf-zK-g43">
                                    <rect key="frame" x="0.0" y="611" width="375" height="51"/>
                                    <constraints>
                                        <constraint firstAttribute="height" constant="51" id="h7p-oO-gAz"/>
                                    </constraints>
                                    <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                    <color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
                                    <nil key="highlightedColor"/>
                                </label>
    <!--​ stuff -->
    

    So, now (sometimes) the key is an attribute. :facepalm:
    What are they trying to do here? It looks like they want to keep a loose-format which doesn't follow a precise schema.


  • Notification Spam Recipient

    @zmaster said in XML, the Apple way:

    Yes, one element is the key and the following one is the value. Brilliant.

    Yes, as soon as I saw that I was like "Fuck that, I'm out. Relationships are based on what order they appear in instead of the XML attribute and hierarchy? It's like they saw XML, thought it was something else, and decided to masquerade it like they thought it was!"...



  • @zmaster said in XML, the Apple way:

    What are they trying to do here? It looks like they want to keep a loose-format which doesn't follow a precise schema.

    Aside from the NO boolean value, I don't think I see the WTF in the second example...? I guess they put all simple-typed properties as attributes as a rule.

    The first one gets weird in that context, but maybe it makes sense if the key can potentially be a not-simple type?



  • @zmaster said in XML, the Apple way:

    If you're familiar with development in the Apple ecosystem, you probably know about Plists and their weird XML format.
    ...
    So, now (sometimes) the key is an attribute. :facepalm:
    What are they trying to do here? It looks like they want to keep a loose-format which doesn't follow a precise schema.

    As someone that isn't an iOS developer, I'd say that

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist ...>
    

    and

    <?xml version="1.0" encoding="UTF-8"?>
    <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version=...>
    

    are different XML document types and can thus represent data in completely different ways.



  • @parody As someone who does do some iOS development, storyboard files and plists are completely separate things. Storyboards are not supposed to be manually edited--they're generated XML (and relatively standard one). Plists are property lists, not really XML at all. As much as I hate everything Apple and XCode, this isn't a :wtf: in and of itself. Why they didn't use straight XML instead of plists, I'm not quite sure. But that's the Apple way--non-standard implementations for everyone!



  • To clarify, I'm not saying Plists and Storyboards are related to one another. I'm just saying that in both cases it looks like XML is being misused.



  • @maciejasjmj said in XML, the Apple way:

    @zmaster said in XML, the Apple way:

    What are they trying to do here? It looks like they want to keep a loose-format which doesn't follow a precise schema.

    Aside from the NO boolean value, I don't think I see the WTF in the second example...? I guess they put all simple-typed properties as attributes as a rule.

    This burns my eyes:

    <nil key="highlightedColor"/>
    

    The first one gets weird in that context, but maybe it makes sense if the key can potentially be a not-simple type?

    This is what it looks like with multiple key-value pairs:

    <dict>
        <key>something</key>
        <string>some value</string>
        <key>something else</key>
        <string>another value</string>
        <key>a third item</key>
        <string>yet another value</string>
    </dict>
    

    The key is always a string, the value could be something else. I understand that Plists by definition can't use a fixed schema but a value-follows-the-key pattern is something I've never seen in XML. As @Tsaukpaetra pointed out, one expects a hierarchy.


  • Discourse touched me in a no-no place

    @zmaster said in XML, the Apple way:

    I'm just saying that in both cases it looks like XML is being misused.

    There's a DTD for plists. It's therefore cromulent but awful.

    The storyboard format looks like it could have a schema quite easily, but nobody's published one and there's quite a few pages out there saying to not edit the files by hand. I'm guessing that there's some tricky constraints (related to placement?) involved that are awkward to capture in a schema. Still, doesn't seem too bad to me.

    Of course, I've seen the wilder end of what people can do with WSDL so anything that doesn't involve twenty interacting schemas all with their own peculiarities is OK to me. 😆



  • @zmaster said in XML, the Apple way:

    To clarify, I'm not saying Plists and Storyboards are related to one another. I'm just saying that in both cases it looks like XML is being misused.

    Oh. It looked like you were complaining about the reuse of the term "key" by a specific company given the italics and emoji and thread title and all.

    FWIW, to me it looks like plists are a stupid use of XML, the storyboards are fine, and there's no reason anyone from a single developer to a huge corporation with many development teams couldn't reuse a term in this way.


  • Winner of the 2016 Presidential Election

    @benjamin-hall said in XML, the Apple way:

    XCode

    Please, do. 🍿


Log in to reply