我正在使用一个Swift包,我不会使用任何Apple库,例如AppKit
和UIKit
。我只能使用Foundation
。在这种情况下,SwiftyJSON的贡献。
现在,我正在为Quick Look创建一个函数。我想用漂亮的打印(颜色和缩进)来显示JSON。
但如何在没有NSAttributedString
或UIColor
的情况下为NSColor
创建属性颜色?有可能吗?
我的尝试:
extension JSON: CustomPlaygroundQuickLookable {
public var customPlaygroundQuickLook: PlaygroundQuickLook {
let myString = "My String Test"
let myAttrString = NSAttributedString(
string: myString,
attributes: ["NSColor": /* ??? */]
)
return .attributedString(myAttrString)
}
}