Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何在没有UIKit或AppKit的情况下为NSAttributedString创建属性颜色?_Json_Swift - Fatal编程技术网

Json 如何在没有UIKit或AppKit的情况下为NSAttributedString创建属性颜色?

Json 如何在没有UIKit或AppKit的情况下为NSAttributedString创建属性颜色?,json,swift,Json,Swift,我在一个Swift软件包中工作,我不可能使用任何苹果库,比如AppKit和UIKit。我只能使用Foundation。在这种情况下,一个供款 现在,我正在创建一个用于快速查看的函数。我想用漂亮的打印(颜色和缩进)显示JSON 但是,如何在没有UIColor或NSColor的情况下为NSAttributedString创建属性颜色呢?有可能吗 我的尝试: extension JSON: CustomPlaygroundQuickLookable { public var customPl

我在一个Swift软件包中工作,我不可能使用任何苹果库,比如
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。当然,这不仅仅是基础。