我如何从本机Swift字符串或NSString中创建CFString
let path:String = NSBundle.mainBundle().pathForResource(name.stringByDeletingPathExtension, ofType:"pdf")
let string:CFString = ??? path
let url:CFURLRef = CFURLCreateWithFileSystemPath(allocator:kCFAllocatorDefault, filePath:string, pathStyle:CFURLPathStyle.CFURLPOSIXPathStyle, isDirectory:false)
最佳答案
只需投放:
var str = "Hello, playground" as CFString
NSString(format: "type id: %d", CFGetTypeID(str))
请注意,您需要使用
import Foundation
才能强制转换as CFString
。否则,如果只有
import CoreFoundation
,则需要强制转换as! CFString
。