Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to clear a UITextField

For an IBOutlet UITextField, does it matter as far as memory management or other reasons how you clear the text value?

textFieldX.text = nil 

or

textFieldX.text = @""; 

In objective-c it is acceptable to message a nil object and @"" is a static NSString *. I'm not sure if every @"" points to the same object in memory or if it allocates a bunch of 1 byte null terminated strings.

Not a big deal, just thought I'd ask the community. Thanks.

like image 832
Brenden Avatar asked Jul 22 '09 22:07

Brenden


1 Answers

Personally I would think less of the memory usage here and more on code-maintainability.

To me, It makes sense that a label always has a string. In the future someone might try to append a labels value, save it in a database, wrap it in xml, etc. An empty NSString in this case makes much more sense to me that a 0x0.

like image 128
Brad The App Guy Avatar answered Sep 20 '22 16:09

Brad The App Guy