如何在swift中从本机swift String或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)
Run Code Online (Sandbox Code Playgroud) 我试图在swift中创建一个CGContext.它编译但在运行时抛出错误.
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace, CGBitmapInfo.AlphaInfoMask)
CGColorSpaceRelease(colorSpace);
....
Run Code Online (Sandbox Code Playgroud)
错误是:
Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; unrecognized; 96 bytes/row.
fatal error: Can't unwrap Optional.None
Run Code Online (Sandbox Code Playgroud) 有人知道处理程序(块)如何在swift中工作吗?我正在尝试运行此代码,但我找不到完成正确语法的任何文档.
let url:NSURL = NSURL(string:"some url")
let request:NSURLRequest = NSURLRequest(URL:url)
let queue:NSOperationQueue = NSOperationQueue()
NSURLConnection.sendAsynchronousRequest(request:request, queue:queue, completionHandler handler:((NSURLResponse!, NSData!, NSError!) -> Void)!)
Run Code Online (Sandbox Code Playgroud)