I want to see the code of the retain, assign and copy setter and getter methods, can anyone please guide me with some useful stack overflow post or any other tutorial links for this. thanx in advance and Regards Saad Ahmad
-
2No one give you whole code. Be specific with your problem. Share your code So that anyone can guide you well. – Umer Abid Oct 01 '12 at 08:59
-
i just want to see the getter setters method code of retain, copy etc, means how they r implemented, and there was a post at stack overflow for this i am trying to find it but not succeeding. – Saad Umar Oct 01 '12 at 09:02
2 Answers
you usually need to claim ownership of your instance variables. See the Objective-C memory management rules. With a retain property, your property setter claims ownership of the new value and relinquishes ownership of the old one. With an assign property, the surrounding code has to do this, which is just as mess in terms of responsibilities and separation of concerns. The reason you would use an assign property is in a case where you can't retain the value (such as non-object types like BOOL or NSRect) or when retaining it would cause unwanted side effects.
Incidentally, in the case of an NSString, the correct kind of property is usually copy. That way it can't change out from under you if somebody passes in an NSMutableString (which is valid — it is a kind of NSString).
Go thriugh with these links. hope you will better understand with these links -
Objective-C 101 (retain vs assign) NSString

- 1
- 1

- 720
- 1
- 7
- 10
This guide explains the principles pretty good. I've used it myself for reference a couple of times.
http://blog.ablepear.com/2010/04/objective-c-tuesdays-instance-variables_20.html

- 11,136
- 14
- 98
- 193