1

I have a need to ensure the user-inputed string in a UITextField is cleared from memory immediately after it has been used. If I set field.text = @"" or nil and let it go out of scope it should ge gone but I am not sure if it is guaranteed to be released immediately and even if it is, I dont think the OS actually clears the data, it seems likely it is just marked as unused and the data in it is still there until overwritten by something else.

The .text property of the field is a normal NSString and I have looked around for ways to get a useable pointer to its contents using the various CFString / CString methods but none of them work. For example CFStringGetCharactersPtr and CFStringGetCStringPtr both either return const-pointers which cant be written to, or often NULL (the docs say it may return null "if the internal storage of the String does not allow this to be returned efficiently") and from my testing it always returns NULL.

Is there anyway to do this?

Robert
  • 5,278
  • 43
  • 65
  • 115
  • 1
    Similar question here: [Sensitive data: NSString VS NSMutableString (iPhone)](http://stackoverflow.com/questions/2361981/sensitive-data-nsstring-vs-nsmutablestring-iphone). I am not voting to close as a duplicate because that question seems to have no definite answer. - I *assume* that there is no satisfying solution for NSString. – Martin R Nov 14 '13 at 09:15
  • Thanks for the comment. As you say the conclusion seems to be that it is not really possible to be sure, and probably not worth the effort even if it was. I found that It the .text property on uitextfield returns true for isKindOfClass: NSMutableString which makes sense since it is user editable. But I cant find a way to actually get at the pointer or use setString or anything. – user2991186 Nov 14 '13 at 11:41
  • 1
    For anyone else wondering: i got a reply from an apple employee at the apple forums and he confirms it is pretty much impossible. His suggestion was to do everything yourself based on UITextInput. – user2991186 Nov 14 '13 at 11:55

1 Answers1

-1

answering my own question to be clear:

I got a reply from an apple employee at the devforums and he confirms it is pretty much impossible. His suggestion was to do everything yourself based on UITextInput and not use NSString or UITextField at all.