macwish
(David.W)
1
Also here: bugs.swift.org
///// main.swift
import Foundation
let name: String = "my name"
let age: UInt32 = 100
let myData: Data = "helloworld".data(using: .utf8)!
let properties: [String: Any] = [
"name": name,
"age": age,
"data": myData
]
do {
// pack
let packedData = try PropertyListSerialization.data(fromPropertyList: properties, format: .binary, options: 0)
// unpack
let unpackedProps = try PropertyListSerialization.propertyList(from: packedData, options: [], format: nil)
guard let newProperties = unpackedProps as? [String: Any] else {
fatalError("error: not a dictionary type")
}
for item in newProperties {
print("# \(item.key) => \(item.value)")
}
} catch {
print("serialize message error: \(error)")
exit(0)
}
print("all done")
the output result on my macOS:
name => my name
age => 100
data => <68656c6c 6f776f72 6c64>
the output result on Ubuntu server:
name => my name
age => 100
data => 0 bytes . // <---- HERE
Problem here is the data decoded is "0 bytes".
Environment info:
Ubuntu 16.04
$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="Bugs : Ubuntu"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ swift --version
Swift version 4.1.2 (swift-4.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
macOS 10.14 Beta (18A314h)
$ swift --version
Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)
Target: x86_64-apple-darwin18.0.0
jrose
(Jordan Rose)
2
Bugs in the Linux implementation of Foundation can go to https://bugs.swift.org under the "Foundation" component. Thanks for finding this!
2 Likes
millenomi
(Aura Lily Vulcano)
3
@macwish: If you end up writing a bug, can you link to it here?
1 Like