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 https://github.com/apple/swift-corelibs-foundation/blob/753e621b5f6c483bd8ef25d7b511a437b6f90f0c/Foundation/PropertyListSerialization.swift#L24-L25

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 https://github.com/apple/swift-corelibs-foundation/pull/1944 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.

Terms of Service

Privacy Policy

Cookie Policy