I have an object w/ an NSString for a property. I would like to use a custom setter for this property so that it always trims all whitespace when the string is set.
Normally this is done with NSString *blah2 = [blah stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];, but I’m not sure about how to formulate this for a custom setter. Isn’t it bad to use autoreleased objects like this in the setter? Should I use a mutable string instead and then convert it to unmutable?
Thanks for any help you guys can provide.
I’m going to presume ARC.
In the setter, I do copy the parameter of the setter in the event someone tries to provide an instance of
NSMutableString– presuming thatFoois not expected to modify the original string.EDIT:
Or if manual reference counting, the setter might be: