What is a property list, and where do you meet one?
Predict first
What do the first bytes of a binary property list look like?
let e = PropertyListEncoder()
e.outputFormat = .binary
print(String(decoding: try e.encode([1, 2]).prefix(8), as: UTF8.self))
- <?xml ve
- bplist00
- {"a":1}
Mental model. A plist is a labelled settings card: simple fields, no room for a database.
A property list is Apple’s simple serialisation format for small structured data: dictionaries and arrays of strings, numbers, booleans, dates and Data. You meet it in Info.plist, entitlements, and under the hood of UserDefaults. Unlike JSON it has first-class Date and Data types, but no null: an optional that is nil is simply omitted.
It has an XML form (human-readable, starts with <?xml) and a binary form (compact, starts with bplist00). PropertyListEncoder and PropertyListDecoder work with Codable; PropertyListSerialization handles untyped trees. Use plists for small config and bundled settings, not for datasets you query.
Binary plists start with the magic string bplist00. The XML form starts with <?xml.
Common traps
- Putting
nilin a plist. There is no null; encoders skip the key. - Editing a binary plist as text. Convert with
plutilfirst, then edit.
They might follow up with
- How do you read a value from
Info.plist?Bundle.main.object(forInfoDictionaryKey:). - Why binary? Smaller and faster to parse than XML, which matters for big bundles.
Related questions
- 2.5.7 What is UserDefaults, what can it store, and why do its typed getters mislead?
- 2.6.1 What is a Bundle, and how do you load a resource from it?
← When would you use JSONSerialization instead of Codable, and what… What is UserDefaults, what can it store, and why do its typed getters… →