Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C: taking index of object in array
    primarykey
    data
    text
    <p>I'm new in Obj C programming, so i will start from beginning I have an array with some NSNumber and NSString elements, i want to replace NSString elems to NSNumber elems. I decide to make this with for in construction get to new NSMutableArray all elements value and to NSMutableIndexSet their indexes, but when i made this i faced with trouble, here it is, i show you my code and log.</p> <pre><code>NSArray *oneMoreStack = [program copy]; NSLog(@" stack=%@",oneMoreStack); NSLog(@" show me index ind=%@",[oneMoreStack indexOfObject:@"x"]); NSMutableIndexSet *myVarIndexesSet; NSMutableArray *myVarsArray; for (id myVarConst in oneMoreStack) { if([myVarConst isKindOfClass:[NSString class]]) { if([myVarConst isEqualToString:@"x"]){ [myVarsArray addObject:myVarConst]; NSLog(@"obj x=%@",myVarConst); [myVarIndexesSet addIndex:[oneMoreStack indexOfObject:myVarConst]]; NSLog(@"ind x=%@",[oneMoreStack indexOfObject:myVarConst]); } } </code></pre> <p>When i run it log show me this:</p> <pre><code>Calculator[6306:f803] stack=( x, 2, "+" ) Calculator[6306:f803] show me index ind=(null) Calculator[6306:f803] obj x=x Calculator[6306:f803] ind x=(null) then crash [NSMutableArray replaceObjectsAtIndexes:withObjects:]: index set cannot be nil </code></pre> <p>So, my question is why does <strong><code>[oneMoreStack indexOfObject:myVarConst]</code></strong> return <strong><code>null</code></strong>? How can i fix it? Thanks. I don't mention this code before because think problem is in getting indexes.</p> <p>after previous part of code goes this part:</p> <pre><code>[stack replaceObjectsAtIndexes:[myVarIndexesSet copy] withObjects:[myVarsArray copy]]; </code></pre> <p>after that crash with error report i mention previously. Thanks. </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.
 

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