Ios ';具有不可分配的字节';在Swift 5中被弃用
我使用了下面的代码块,效果很好。使用swift 5,我收到以下不推荐的警告: 不推荐使用“withUnsafeMutableBytes”:使用Ios ';具有不可分配的字节';在Swift 5中被弃用,ios,deprecated,swift5,Ios,Deprecated,Swift5,我使用了下面的代码块,效果很好。使用swift 5,我收到以下不推荐的警告: 不推荐使用“withUnsafeMutableBytes”:使用 withUnsafeMutableBytes(:(UnsafeMutableRawBufferPointer)抛出 ->R)改为重新旋转->R data.withUnsafeMutableBytes{(数据字节:UnsafeMutablePointer)->Void in _=CCRandomGenerateBytes!(数据字节,大小) } 如何避免
withUnsafeMutableBytes(:(UnsafeMutableRawBufferPointer)抛出
->R)改为重新旋转->R
data.withUnsafeMutableBytes{(数据字节:UnsafeMutablePointer)->Void in
_=CCRandomGenerateBytes!(数据字节,大小)
}
如何避免此警告。您应该使用:
data.withUnsafeBytes { $0.load(as: UInt8.self) }
您还可以使用以下命令生成随机UInt8:
UInt8.random(in: .min ... .max)
你应使用:
data.withUnsafeBytes { $0.load(as: UInt8.self) }
您还可以使用以下命令生成随机UInt8:
UInt8.random(in: .min ... .max)
你可以试试这个
data.withUnsafeMutableBytes { (ptr) in
if let rawPtr = ptr.baseAddress {
let _ = CCRandomGenerateBytes(rawPtr, size)
}
}
你可以试试这个
data.withUnsafeMutableBytes { (ptr) in
if let rawPtr = ptr.baseAddress {
let _ = CCRandomGenerateBytes(rawPtr, size)
}
}