Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>You're creating a pointer that is initialized to <code>nil</code>. If you're familiar with C or Java, then <code>nil</code> is basically the same thing as <code>NULL</code> or <code>null</code> -- it's effectively a pointer to nothing.</li> <li>Yes. <code>@"StarWars"</code> is called a "string literal". Think of a string literal as a "permanent" string that is stored by the program, and <code>gName</code> (in this case) is a pointer to the memory location of that string.</li> <li>Yep -- that line makes sure that the incoming <code>gName</code> is not the same as the object's <code>geekName</code> variable. Assume that check wasn't there, and <code>gName</code> and <code>geekName</code> pointed to the same string -- then the next line would release that string, which could make the <em>next</em> line invalid (it would be copying a released string -- very bad!).</li> <li>Assuming <code>geekName</code> is still <code>nil</code>, then yes, nothing is released; or rather, the <code>release</code> message is sent to the <code>nil</code> object, which does nothing with the message. (Unlike C or Java, in Objective-C, you can send messages to <code>nil</code> -- but all such messages are ignored, and <code>nil</code> is the return value from all such messages).</li> <li>You create a copy of <code>gName</code> in case <code>gName</code> is <em>really</em> an instance of an <code>NSMutableString</code> -- you don't want other code to mutate the string that you are treating as immutable. But what happens to the <em>original</em> object pointed to by <code>gName</code>? Well, it depends on what the caller does with it. It could be released, it could be retained, it could be passed to another object...you don't really know. In this particular case, since <code>gName</code> points to the string literal "StarWars", nothing happens to that object (since it's a string literal -- see above). And the pointer itself is only valid in the scope of this method, and goes away once the method returns.</li> </ol>
    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. 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