I am trying to store a UIColor
value in UIPasteboard.general.color
property. When I try to access that property it always returns nil on the simulator (haven't tried on device). I am using iOS10.0 and Swifth 3.2.2 and latest XCode 9.0:
UIPasteboard.general.color = color
if let color = UIPasteboard.general.color {
print("color=\(color)")
}
else {
print("no color")
}
I tried using the colors
property, but the behavior is the same, but strange: hasColors
returns true, and colors
is not nil, but the count of elements is 0
:
UIPasteboard.general.colors = [color]
guard
UIPasteboard.general.hasColors, // ok
let colors = UIPasteboard.general.colors, // ok
0 < colors.count // fail
else {
print("no color")
return
}
print("color=\(colors[0])")
I must be doing something wrong here. I am using the convenience properties color
and colors
. Here are Apple's specs I'm following: https://developer.apple.com/documentation/uikit/uipasteboard/1622085-color and https://developer.apple.com/documentation/uikit/uipasteboard/1622078-colors