Replies: 2 comments 3 replies
-
Ok, I looked at the code a bit and think it could be related to this: public convenience
init(data: Data) throws {
self.init()
// load as raw NS objects
// just a default, will be replaced...
var getFormat: PropertyListSerialization.PropertyListFormat = .xml // any way to have .binary? |
Beta Was this translation helpful? Give feedback.
-
The data blobs may be correctly encoded binary plists but they do not have a dictionary as the top-level element. By plist spec, the top level object can by any PList type: Since it's been on my to-do list for a while, I spent the day refactoring the library to fully accommodate plists that use a top-level (root) element other than Dictionary. It's pushed to main now as release 2.0.0. This may solve your issue since my best guess is that those binary plist chunks are plists with non-dictionary roots (could be an Array, or even a single value like String, Int, etc.) If you like, check out the 2.0.0 branch and try that. The API has changed a bit. There is now an The old vanilla So if you know what a plist's root type is ahead of time, before reading the file, then just use the specialized The new documentation further explains this. So a revised version of your code snippet may look like this: let plist = try DictionaryPList(data: data) // < -- 💡 use dictionary-specialized plist here
for (key, value) in plist.root.value {
switch value {
// …
case let val as Data:
guard let sublist = try? AnyPList(data: val) else { // < -- 💡 use AnyPList here
print("Could not create list for key \(key)")
continue
}
// 💡 unwrap the AnyPList instance to its root element form here
switch sublist.plist {
case .arrayRoot(let arrayPList):
print(arrayPList.storage) // prints the array
// ... can try remaining root type cases here ...
}
break
}
} At the very least this will allow you to introspect what the data blobs are. If you find out that there is reasonable expectation for them to be of a certain root type (like maybe some are always arrays) then you can replace |
Beta Was this translation helpful? Give feedback.
-
Hello,
First of all, thanks a lot for this library, it looks very good and is very intuitive.
However, I'm not able to do something, probably because I'm missing something. I wrote a Swift program to execute the command
defaults export -app Transmission -
and create a PList object using the output of that command. This works fine, I'm able to read all the keys and values.But if I print the values that have the "data" type using
String.init(data: val, encoding: String.Encoding.ascii)
I can see something like:Optional("bplist00Ô\u{01}\u{02}\u{03}\...
.So I was wondering if some keys of type "data" store their value as another Plist (in binary format) and therefore tried to create a second PList object using that data but it didn't work:
Is it possible to do that? Am I correct assuming that the "bplist" is a binary plist and can be parsed?
Thanks again,
nyg
Beta Was this translation helpful? Give feedback.
All reactions