So i'm going to send data back and forth between 2 applications and i thought since it's A LOT of data in different models i can use a UIPasteboard
. However i can't get it to work. Here's the code and issue.
struct TestModel {
var value1: Int = 0
var value2: String = "hi"
}
class ViewController: UIViewController {
@IBOutlet weak var redView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let model = TestModel(value1: 1, value2: "hello")
let testModel = Mirror.init(reflecting: model)
guard let paste = UIPasteboard.init(name: UIPasteboard.Name(rawValue: "test1"), create: true) else {return}
let items = testModel.children.map({
return [$0.label ?? "noLabel": $0.value]
})
print(items)
paste.addItems(items)
print(paste.items[0]["value1"])
}
}
print(items)
gives me the following:
[["value1": 1], ["value2": "hello"]]
So everything is working so far.
print(paste.items[0]["value1"])
however gives me:
<OS_dispatch_data: data[0x2835d3cc0] = { leaf, size = 43, buf = 0x102f18000 }>
And i have no clue how to unwrap this, i've tried unwrapping it to Int
, String
, Data
, NSData
and everything, but nothing seem to work.. so what is going on?