PropertyListDecoder/Encoder?

I’m trying to port some mac/iOS swift code over to also compile and run on linux. However one of the files I’m working with references PropertyListDecoder in order to decode some propertylist data we have in our library, and it’s failing to compile since PropertyListDecoder doesn’t appear to be implemented in the corelibs-foundation project. Is this an oversight, or intentional? Are there any workarounds I can do (short of re-encoding our data in JSON which i’d prefer not to do) to get access to property list decoding on linux?

Thanks!

···

--
Kevin Lundberg

Hi Kevin,

It's unintentional, in the sense that noone has done the work yet to
implement the PropertyListDecoder in corelibs-foundation.

However, the Darwin implementation is actually open source - see
https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/PlistEncoder.swift
- so we should be able to reuse that code. It might not be a straight
copy and paste, but the bulk of the work is ready and done...

PRs welcome!

Thanks,
Ian

···

On 16 November 2017 at 20:54, Kevin Lundberg via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I’m trying to port some mac/iOS swift code over to also compile and run on linux. However one of the files I’m working with references PropertyListDecoder in order to decode some propertylist data we have in our library, and it’s failing to compile since PropertyListDecoder doesn’t appear to be implemented in the corelibs-foundation project. Is this an oversight, or intentional? Are there any workarounds I can do (short of re-encoding our data in JSON which i’d prefer not to do) to get access to property list decoding on linux?

Thanks!

--
Kevin Lundberg

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
Ian Partridge

1 Like

Thank you! I found this shortly before your message, and I’m working on that right now in my project (and it is definitely not a simple copy paste but so far it seems manageable).

···

--
Kevin Lundberg

On Nov 16, 2017, at 4:12 PM, Ian Partridge <ian@poncho.org.uk> wrote:

Hi Kevin,

It's unintentional, in the sense that noone has done the work yet to
implement the PropertyListDecoder in corelibs-foundation.

However, the Darwin implementation is actually open source - see
https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/PlistEncoder.swift
- so we should be able to reuse that code. It might not be a straight
copy and paste, but the bulk of the work is ready and done...

PRs welcome!

Thanks,
Ian

On 16 November 2017 at 20:54, Kevin Lundberg via swift-corelibs-dev > <swift-corelibs-dev@swift.org> wrote:

I’m trying to port some mac/iOS swift code over to also compile and run on linux. However one of the files I’m working with references PropertyListDecoder in order to decode some propertylist data we have in our library, and it’s failing to compile since PropertyListDecoder doesn’t appear to be implemented in the corelibs-foundation project. Is this an oversight, or intentional? Are there any workarounds I can do (short of re-encoding our data in JSON which i’d prefer not to do) to get access to property list decoding on linux?

Thanks!

--
Kevin Lundberg

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
Ian Partridge

May/may not be useful - unfortunately couldn’t get it working on Linux so had to close.

···

Sent from my iPhone

On 16 Nov 2017, at 21:18, Kevin Lundberg via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Thank you! I found this shortly before your message, and I’m working on that right now in my project (and it is definitely not a simple copy paste but so far it seems manageable).
--
Kevin Lundberg

On Nov 16, 2017, at 4:12 PM, Ian Partridge <ian@poncho.org.uk> wrote:

Hi Kevin,

It's unintentional, in the sense that noone has done the work yet to
implement the PropertyListDecoder in corelibs-foundation.

However, the Darwin implementation is actually open source - see
https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/PlistEncoder.swift
- so we should be able to reuse that code. It might not be a straight
copy and paste, but the bulk of the work is ready and done...

PRs welcome!

Thanks,
Ian

On 16 November 2017 at 20:54, Kevin Lundberg via swift-corelibs-dev >> <swift-corelibs-dev@swift.org> wrote:

I’m trying to port some mac/iOS swift code over to also compile and run on linux. However one of the files I’m working with references PropertyListDecoder in order to decode some propertylist data we have in our library, and it’s failing to compile since PropertyListDecoder doesn’t appear to be implemented in the corelibs-foundation project. Is this an oversight, or intentional? Are there any workarounds I can do (short of re-encoding our data in JSON which i’d prefer not to do) to get access to property list decoding on linux?

Thanks!

--
Kevin Lundberg

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
Ian Partridge

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

If anyone comes across this here looking for a solution like I did, here's a short description of a simple workaround using the Darwin code @IanPartridge linked to above: Swift: Make PropertyListDecoder available on Linux — finestructure

Yes, I did something like that for a project were I needed the PropertyListDecoder on Linux.

@Tony_Parker @millenomi Now that as bridging is working on cross-platform Swift is there any difficulty on moving PlistEncoder.swift to Swift Foundation?

Yes, my hope is that it is easier now. I haven't had the chance to try it myself yet though.

@pvieito I just tried to use your Shortcut code and I could build it, but strangely, it generates errors when I put that module in my project:

.../PropertyListCoder.swift:266:20: error: type '_PlistKeyedEncodingContainer<K>' does not conform to protocol 'KeyedEncodingContainerProtocol'
fileprivate struct _PlistKeyedEncodingContainer<K : CodingKey> : KeyedEncodingContainerProtocol {
                   ^
.../PropertyListCoder.swift:333:26: note: candidate has non-matching type '<K> () -> Encoder'
    public mutating func superEncoder() -> Encoder {
                         ^
.../PropertyListCoder.swift:337:26: note: candidate has non-matching type '<K> (forKey: _PlistKeyedEncodingContainer<K>.Key) -> Encoder' (aka '<τ_0_0> (forKey: τ_0_0) -> Encoder')
    public mutating func superEncoder(forKey key: Key) -> Encoder {
                         ^
Swift.KeyedEncodingContainerProtocol:38:19: note: protocol requires function 'superEncoder()' with type '() -> Encoder'; do you want to add a stub?
    mutating func superEncoder() -> Encoder
                  ^
Swift.KeyedEncodingContainerProtocol:39:19: note: protocol requires function 'superEncoder(forKey:)' with type '(_PlistKeyedEncodingContainer<K>.Key) -> Encoder'; do you want to add a stub?
    mutating func superEncoder(forKey key: Self.Key) -> Encoder
                  ^
.../PropertyListCoder.swift:342:20: error: type '_PlistUnkeyedEncodingContainer' does not conform to protocol 'UnkeyedEncodingContainer'
fileprivate struct _PlistUnkeyedEncodingContainer : UnkeyedEncodingContainer {
                   ^
.../PropertyListCoder.swift:412:26: note: candidate has non-matching type '() -> Encoder'
    public mutating func superEncoder() -> Encoder {
                         ^
Swift.UnkeyedEncodingContainer:38:19: note: protocol requires function 'superEncoder()' with type '() -> Encoder'; do you want to add a stub?
    mutating func superEncoder() -> Encoder
                  ^
.../Config/PropertyListCoder.swift:541:34: error: argument type '_PlistEncoder' does not conform to expected type 'Encoder'
            try value.encode(to: self)
                                 ^~~~
                                      as! Encoder

I am a bit puzzled by the difference of behavior. Any idea about what I could be doing wrong ?

Thanks !

Update: It seems it has something to do with some conflict with my code. If I put it in a different package and namespace, it works fine.