I'm puzzeled by the behavior of the automatic coercion. Specifically
when something will work and when it will not. It at least has something
to do with the platform. That much I have tracked down.

I've attached a file, bridge.swift, that on Linux will fail to compile
with the error: cannot convert value of type 'NSData' to type 'Data' in
coercion. However, on Darwin it compiles just fine.

(The contents of the file just incase it gets stripped)

import Foundation

let md = NSData(bytes: [0x0D, 0x0A, 0x0D, 0x0A], length: 4)
_ = md as Data

On Linux the `md` has a method `_bridgeToSwift()` that returns the
`Data` I am looking for. But of course, the Darwin version does not.

Which begs the question what is the cross-platform way of doing things?
I'm hoping it is not `if #os(Linux)`...

Attachment: bridge.swift
Description: Binary data

swift-users mailing list

Reply via email to