Json 如何在没有UIKit或AppKit的情况下为NSAttributedString创建属性颜色?
我在一个Swift软件包中工作,我不可能使用任何苹果库,比如Json 如何在没有UIKit或AppKit的情况下为NSAttributedString创建属性颜色?,json,swift,Json,Swift,我在一个Swift软件包中工作,我不可能使用任何苹果库,比如AppKit和UIKit。我只能使用Foundation。在这种情况下,一个供款 现在,我正在创建一个用于快速查看的函数。我想用漂亮的打印(颜色和缩进)显示JSON 但是,如何在没有UIColor或NSColor的情况下为NSAttributedString创建属性颜色呢?有可能吗 我的尝试: extension JSON: CustomPlaygroundQuickLookable { public var customPl
AppKit
和UIKit
。我只能使用Foundation
。在这种情况下,一个供款
现在,我正在创建一个用于快速查看的函数。我想用漂亮的打印(颜色和缩进)显示JSON
但是,如何在没有UIColor
或NSColor
的情况下为NSAttributedString
创建属性颜色呢?有可能吗
我的尝试:
extension JSON: CustomPlaygroundQuickLookable {
public var customPlaygroundQuickLook: PlaygroundQuickLook {
let myString = "My String Test"
let myAttrString = NSAttributedString(
string: myString,
attributes: ["NSColor": /* ??? */]
)
return .attributedString(myAttrString)
}
}
要设置颜色(
UIColor
或NSColor
),需要使用诸如NSForegroundColorAttributeName
之类的键。密钥本身需要AppKit或UIKit。@rmaddy是的。。。我将NSForegroundColorAttributeName
替换为“NSColor”
,希望能工作。。。你有办法解决这个问题吗?我想创建一个漂亮的JSON打印。您可以使用CoreText,然后颜色和字体将为CGColor和CTFont。当然,这不仅仅是基础。