Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playground: Use of unresolved identifier 'NSColor'

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?

like image 437
user2988464 Avatar asked Nov 30 '22 01:11

user2988464


1 Answers

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:

enter image description here

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()
like image 107
GoZoner Avatar answered Dec 05 '22 07:12

GoZoner