Is it bad to create @properties for private variables just for the memory management benefits?
It seems messy and wrong to have public facing @properties for many private variables.
(Mainly, I am releasing private ivars during low memory conditions using the respective "event" methods.)
Example: I usually do this to release a private ivar:
[name release]; name = nil;
But with @properties, I can do this:
self.name = nil;
Later in my code, will do this, hence the need to set to nil:
if( !name)
name = [[NSString alloc] initWithFormat:@"Hi %@",inputName];
An alternative is to keep the property private. You can use the following code (in your .m file) to make the property only accessible within your class:
#import "MyClass.h"
@interface MyClass ()
@property (retain) NSString* privateString;
@end
@implementation MyClass
@synthesize privateString;
// Your code here
@end
Now you've got the ease of a property, but other classes still can't access it, even if they import your .h file!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With