我只是将我的iOS应用程序代码更新为Swift 3,这一行让我感到高兴:
let dataProvider:CGDataProvider? = CGDataProviderCreateWithData(nil, maskImagePixelData!, maskImagePixelData!.count, nil)
在我之前使用的Swift版本中有效,现在它抛出了这个错误:
Nil与预期的参数类型不兼容' CGDataProviderReleaseDataCallback' (又名' @convention(c)(可选< UnsafeMutableRawPointer>,UnsafeRawPointer,Int) - > {}')
我找不到CGDataProviderCreateWithData
(!)的文档,但签名也让我感到困惑:
CG_EXTERN CGDataProviderRef __nullable CGDataProviderCreateWithData(
void * __nullable info, const void * cg_nullable data, size_t size,
CGDataProviderReleaseDataCallback cg_nullable releaseData)
是否有nil
的简单替代品,还是需要进入某种UnsafeMutableRawPointer
?
答案 0 :(得分:4)
知道了:
let releaseMaskImagePixelData: CGDataProviderReleaseDataCallback = { (info: UnsafeMutableRawPointer?, data: UnsafeRawPointer, size: Int) -> () in
// https://developer.apple.com/reference/coregraphics/cgdataproviderreleasedatacallback
// N.B. 'CGDataProviderRelease' is unavailable: Core Foundation objects are automatically memory managed
return
}
var dataProvider:CGDataProvider? = CGDataProvider(dataInfo: nil, data: maskImagePixelData!, size: maskImagePixelData!.count, releaseData: releaseMaskImagePixelData)
使用CGDataProvider.init
替换CGDataProviderCreateWithData
文档为here