I tried to play with playground in Xcode6-Beta4, and type the following:
import UIKit
let color = NSColor.blueColor()
and the error is:
Use of unresolved identifier 'NSColor'
Can someone explain why?
If you are developing for iOS and thus using import UIKit
(as your code shows), then the appropriate color interface comes from UIColor
. As such:
For code meant to work in both iOS and OS X you can use:
#if os(macOS) || targetEnvironment(macCatalyst)
import AppKit
typealias ColorType = NSColor
#elseif os(iOS)
import UIKit
typealias ColorType = UIColor
#endif
let color = ColorType.blackColor()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With