PropertyListSerialization on Linux doesn't compile with mutableContainersAndLeaves

I couldn't find any particular reason for this, but a function call on Linux of

let serialized = try PropertyListSerialization.propertyList(
    from: plistXML,
    options: .mutableContainersAndLeaves,
    format: &propertyListFormat
)

doesn't compile when running on the Swift docker image, giving an error of extra argument 'format' in call format: &propertyListFormat. But:

let serialized = try PropertyListSerialization.propertyList(
    from: plistXML,
    options: [],
    format: &propertyListFormat
)

compiles fine. Anything I'm missing?

I experimented on macOS, not Linux, but it kept hitting the error you describe until I got the argument for format declared correctly:

let plistXML = Data()
var propertyListFormat: PropertyListSerialization.PropertyListFormat = .xml // Some nonā€nil placeholder.

let serialized = try PropertyListSerialization.propertyList(
    from: plistXML,
    options: .mutableContainersAndLeaves,
    format: &propertyListFormat
)

So the compiler may be diagnosing your problem incorrectly; it may instead have something to do with a mismatched type being passed to one of the arguments.

Yeah, code looks the same and that compiles fine on MacOS but still not on Linux.

Although you bring up a good point if it was giving you the same error, might be something with how UnsafeMutablePointer<PropertyListFormat>? is treated.

How do you have propertyListFormat declared? My mistake had been to declare it as optional. But UnsafeMutablePointer<PropertyListFormat>? is an optional pointer, not a pointer to an optional format. (See the comment in the earlier code sample. You may have to scroll to the right.)

If you extract the mutableContainersAndLeaves reference you end up with this error:

xcodeproj/Sources/xcodeproj/Project/XcodeProj.swift:85:48: error: 'mutableContainersAndLeaves' is inaccessible due to 'internal' protection level
        let a = PropertyListSerialization.ReadOptions.mutableContainersAndLeaves
                                                      ^

Which makes sense because it turns out these are declared internally swift-corelibs-foundation/PropertyListSerialization.swift at 753e621b5f6c483bd8ef25d7b511a437b6f90f0c Ā· apple/swift-corelibs-foundation Ā· GitHub

It makes sense that this works on macOS because it's not using swift-corelibs-foundation. I'm not sure if this was intentional or not, but I've submitted Make PropertyListSerialization.MutabilityOptions constants public by keith Ā· Pull Request #1944 Ā· apple/swift-corelibs-foundation Ā· GitHub for discussion

In the meantime you could work around this on Linux by using what that constant refers to MutabilityOptions(rawValue: 2) directly.

2 Likes

Yup, thatā€™d be it.