ios - Playground : Use of unresolved identifier 'NSColor'

标签 ios swift xcode6 swift-playground

我尝试在 Xcode6-Beta4 中玩 playground,并输入以下内容:

import UIKit
let color = NSColor.blueColor()

错误是:

Use of unresolved identifier 'NSColor'

谁能解释一下为什么?

最佳答案

如果您正在为 iOS 开发并因此使用 import UIKit(如您的代码所示),则相应的颜色界面来自 UIColor。因此:

enter image description here

对于旨在同时在 iOS 和 OS X 中工作的代码,您可以使用:

#if os(macOS) || targetEnvironment(macCatalyst)
import AppKit
typealias ColorType = NSColor
#elseif os(iOS)
import UIKit
typealias ColorType = UIColor
#endif

let color = ColorType.blackColor()

关于ios - Playground : Use of unresolved identifier 'NSColor' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25224874/

相关文章:

ios - Firebase 3.6.0 (Auth) - 使用 Swift 3.0 检测特定错误

ios - KVO on Swift 的计算属性

swift - 如何将数据导入 Realm

ios - 如何在 UISlider 中实现 sender.selected if 语句?

ios - CoreData执行后台任务冲突

ios - 将 UIView 嵌入到 UITableViewCell 中

arrays - 从特定元素添加的数组中的 Swift 求和数

swift - Table View 不反弹

objective-c - iOS 7.1 - 7.1.2 所有者无法打开我的游戏

ios - 保存与 Realm 的多对多关系