I'm trying to use this code from the Realm documentation:
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
}
On its own, this will compile. However as withUnsafeMutableBytes completes with a closure, instead of this type of code flow:
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
}
// do something using the encryption key
I want to change it to this:
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
// do something using the encryption key
}
But I just cannot add anything else to the closure without starting to get errors, for example its not possible to simply add just a print statement:
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
print("WTF!")
}
Will give this error:
If I try to get rid of the _, then its this error:
I found this thread https://forums.developer.apple.com/thread/51439
But after trying what's in that thread, which doesn't compile actually compile, and so after applying XCode auto-corrections to, I just end up with one error after another after another after another and its driving me nuts.