How to convert a swift String to CFString

后端 未结 5 993
梦谈多话
梦谈多话 2020-12-30 19:34

How can i create a CFString from a native swift String or NSString in swift

    let path:String = NSBundle.mainBundle().pathForResource(name.stringByDeleting         


        
5条回答
  •  清歌不尽
    2020-12-30 19:43

    If you want to convert a non-literal string, you have to cast it to NSString.

    let replacement = "World"
    let string = "Hello, \(replacement)"
    
    let cfstring:CFString = string as NSString
    

    Swift knows how to convert a swift string to an NSString and an NSString to a CFString, but seems not to know how to do both steps in one.

提交回复
热议问题