【发布时间】:2017-03-30 18:39:40
【问题描述】:
我在 GitHub 上找到了一个不错的 360 播放器项目。 https://github.com/iosdevzone/360Video
当我将它转换到最后一个 Swift3 语法时,我得到了这个 error:
“无法使用类型为 '(UnsafeMutableRawPointer!) 的参数列表调用类型为 'UnsafeMutablePointer' 的初始化程序!” 和
“'UnsafeMutablePointer' 的重载存在这些部分匹配的参数列表:(RawPointer), (OpaquePointer), (OpaquePointer?), (UnsafeMutablePointer), (UnsafeMutablePointer?)"
我也得到了这篇关于如何迁移的文章,但我自己修复它太难了。 https://swift.org/migration-guide/se-0107-migrate.html
它发生在这段代码中:
// MARK: - 纹理
func loadTexture(_ image: UIImage?)
{
guard let image = image else
{
return
}
let width = image.cgImage?.width
let height = image.cgImage?.height
// 有错误! 让 imageData = UnsafeMutablePointer(calloc(Int(width! * height! * 4), sizeof(GLubyte)))
let imageColorSpace = image.cgImage?.colorSpace
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
let gc = CGContext(data: imageData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 4 * width, space: imageColorSpace, bitmapInfo: bitmapInfo.rawValue)
gc.draw(image.cgImage, in: CGRect(x: 0, y: 0, width: CGFloat(width), height: CGFloat(height)))
self.updateTexture(CGSize(width: width, height: height), imageData: imageData)
free(imageData)
}
【问题讨论】:
标签: ios xcode migration swift3