I have the following code written in Swift 2.2:
let keyData = NSMutableData(length: 64)!
SecRandomCopyBytes(kSecRandomDefault, 64, UnsafeMutablePointer
I recommend you to work with Data
rather than NSData
in Swift 3.
var keyData = Data(count: 64)
let result = keyData.withUnsafeMutableBytes {mutableBytes in
SecRandomCopyBytes(kSecRandomDefault, keyData.count, mutableBytes)
}
withUnsafeMutableBytes(_:)
is declared as a generic method, so, in simple cases such as this, you can use it without specifying element type.