You'd have to get really low-level. The most common Swift constructs for this sort of thing (
String
,
Array<UInt8>
) are value types but the underlying storage typically comes from a heap block that you don't have access to. OTOH, there's nothing stopping you from calling low-level memory allocators in Swift, at which point you could scrub the memory before freeing it.
The problem with doing this is that it's not practical. Let's say you need to ask the user for a password; how are you going to do that? Most folks would use a text field with the secure (
secureTextEntry
) flag set. How does that field return its value? Via an
NSString
. Can you reliably scrub
that memory? No.
The same sort of logic applies to network I/O, file I/O, the keychain, and everything else you might want to do with your security-sensitive data.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"