Convert CFString to NSString - Swift

前端 未结 3 1296
终归单人心
终归单人心 2021-01-03 22:55

I\'m trying to write a program that will scan for available serial ports and present them in a popup menu. Why can I not take the CFString straight from the

3条回答
  •  粉色の甜心
    2021-01-03 23:58

    As for me, I like to make extentions and use them afterwards. It seems convenient and clear to read:

    Extention:

    extension CFString {
        var string: String {
            return self as String
        }
    }
    

    Usage:

    let specificQueryPart: [String: NSObject] = [
                kSecReturnData.string: true as NSObject,
                kSecAttrService.string: key as NSObject,
                kSecMatchLimit.string: kSecMatchLimitOne
            ]
    

提交回复
热议问题