
let value = UnsafePointer<UInt32>(array1).pointee
‘init’ is unavailable: use ‘withMemoryRebound(to:capacity:_)’ to temporarily vIEw memory as another layout-compatible type.
在swift2中它就像
let value = UnsafePointer<UInt32>(array1).memory
有人可以解释一下吗?
对不起,我对swift3很新
我做了更改后
let abc = UnsafePointer<UInt32>(array1).withMemoryRebound(to: <#T##T.Type#>,capacity: <#T##Int#>,<#T##body: (UnsafeMutablePointer<T>) throws -> Result##(UnsafeMutablePointer<T>) throws -> Result#>)
但仍然应该对变量有什么价值?对不起,我有搜索但很糟糕,我找不到解决方案
解决方法 你可以试试这个:let rawPointer = UnsafeRawPointer(array1)let pointer = rawPointer.assumingMemoryBound(to: UInt32.self)let value = pointer.pointee
原始指针是用于访问非类型数据的指针.
assumeMemoryBound(to :)可以从UnsafeRawPointer转换为UnsafePointer< T>.
参考:Swift 3.0 Unsafe World
总结以上是内存溢出为你收集整理的ios – UnsafePointer不再适用于swift 3全部内容,希望文章能够帮你解决ios – UnsafePointer不再适用于swift 3所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)