|
|
#1 |
|
How do I retain a readonly property?
Let's say that I jave this property:
Code:
@property(nonatomic,strong,readonly) NSMutableArray* tags; Code:
self.tags=[NSMutableArray new]; |
|
|
|
0
|
|
|
#2 | |
|
Quote:
And please don't use "new". Use one of the convenience methods, like [NSMutableArray array]. |
||
|
|
0
|
|
|
#3 | |
|
Quote:
|
||
|
|
0
|
|
|
#4 | |
|
Quote:
---------- new will alloc, init, and retain the object. array should not retain the object beyond the method. This is important when using manual memory management.
__________________
My App: CameraTime - Time lapse photography for novice and advanced users.
Last edited by xStep; Dec 23, 2012 at 10:03 AM. |
||
|
|
0
|
|
|
#5 |
|
I don't know that anyone answered the question. Using the . notation to access a property this is converted to [self propertyName] on an access or [self setPropertyName] on assignment. Normally using self.propertyName in methods of the class is fine, but obviously when there's no setter you can't use this syntax. When you are in methods in the object itself, propertyName = someValue should be fine. The readonly really means "other people". If you weren't using properties, and you had an instance variable, and wrote an accessor, but no mutator, you wouldn't have any problem. You'd just assign to the variable in your instance methods. The properties are just syntactic sugar for the same thing. All the modifiers just describe what getter/setter methods are generated, whether they make copies, how they manage memory, etc. You could do all of this yourself, the properties are just a shortcut.
TL;DR: Remove self. and proceed. -Lee |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 11:29 AM.







Linear Mode
