From Objective-C, I could do this:
NSMutableData *data = [NSMutableData dataWithLength:length]; int result = SecRandomCopyBytes(kSecRandomDefault, length, data.mutableBytes);
When trying this in Swift, I have the following:
let data = NSMutableData(length: Int(length)) let result = SecRandomCopyBytes(kSecRandomDefault, length, data.mutableBytes)
but I get this compiler error:
'Void' is not identical to 'UInt8'
The data.mutableBytes parameter is rejected because the types do not match, but I cannot figure out how to force the parameter (and I assume that it is somehow safe).
source share