Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you cast the returned object to your object type (<code>MyObject</code>)?</p> <p>You should do something like:</p> <pre><code>((MyObject*)[mutableArray objectAtIndex:0]).age = 20; </code></pre> <p>The reason you're not getting any errors when using <code>[[mutableArray objectAtIndex:0] name]</code> syntax is that you're calling a method on the returned object (which is of type <code>id</code>), and <code>id</code> s tend to not choke in the compile-time if you call a (yet) non-existant method on them. At the run-time, <code>[mutableArray objectAtIndex:0]</code> <em>might</em> resolve to type <code>MyObject</code> an in that case, the message <code>[obj name]</code> has a proper implementation (<code>IMP</code>). If it doesn't resolve to <code>MyObject</code>, your app will crash.</p> <p>And note that the reason you're not even getting a compile-time warning is that Xcode knows that there is at least 1 class in your codebase that implements the method <code>name</code>, and it trusts you with calling this method <em>only</em> on instances of that class. if you do something like <code>((MyObject*)[mutableArray objectAtIndex:0]).ageeeeee = 20;</code>, it'll give you a warning as there's a very good chance that it'll crash (no class in your app implements the method <code>ageeeeee</code> <em>statically</em>). </p> <p>The type <code>id</code> does not have a property <code>name</code>, and that's why you can't use dot syntax.</p> <p>Actually, this incident shows perfectly why ObjC is called a dynamic language!</p>
    singulars
    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