Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) @property is a special way to define getter- and setter-methods, or as we call them accessors in Objective-C. Your first snippet just declares an array for which you have to declare and write accessors yourself. For example <code>setMyArray:</code> and <code>myArray</code>.<br> Using @property will declare your accessors for you and is equivalent to declaring <code>setMyArray:</code> and <code>myArray</code> yourself. It is the preferred way to declare accessors since Objective-C 2.0. Note that you still have to declare the property (in your case myArray) yourself. </p> <p>2) You first need to know about @synthesize. Remember that @property DECLARES the accessors for your property, @synthesize will IMPLEMENT them. When you use an @property in your @interface you mostly likely write an @synthesize in @implementation. Using @synthesize is equivalent to implementing <code>setMyArray:</code> and <code>myArray</code>.<br> The attributes <code>(nonatomic, retain)</code> tell the compiler, among others, how the memory management should work and therefore how the methods will be implemented. Note that you never actually see these accessors, but be assured that they are there and ready for you to be used.</p> <p>To read more on that topic I recommend reading Section 9 on Properties from the following <a href="http://cocoadevcentral.com/d/learn_objectivec/">Tutorial</a> or buy a <a href="http://www.bignerdranch.com/book/cocoa_programming_for_mac_os_x_th_edition_">Book</a> that covers an Introduction to Objective-C.</p> <p>Also you should familiarize yourself with at least the following attributes:</p> <ul> <li>Access <ul> <li>Choose <code>readwrite</code> (default) or <code>readonly</code>. If <code>readonly</code> is set, ONLY the getter methods will be available.</li> </ul></li> <li>Setter Memory Management <ul> <li><code>assign</code> (default), simply assigns the new value. You mostly likely only use this with primitive data types.</li> <li><code>retain</code>, releases the old value and retains the new. If you use the garbage collector, <code>retain</code> is equivalent to <code>assign</code>. Why? The manual release of the old value will be done by the garbage collector.</li> <li><code>copy</code> will copy the new value and release the old value. This is often used with strings.</li> </ul></li> <li>Threading <ul> <li><code>atomic</code> (default) will ensure that the setter method is atomic. This means only one thread can access the setter at once.</li> <li><code>nonatomic</code>, use this when you don't work with threads.</li> </ul></li> </ul> <p><a href="http://cocoawithlove.com/2010/06/assign-retain-copy-pitfalls-in-obj-c.html">This post</a> gives you a good introduction to memory management and <code>assign</code>, <code>retain</code> and <code>copy</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload