Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, this answer got all cluttered with edits. I've edited it to be more clear, at the possible expense of understanding the thread of how we arrived at the final answer.</p> <p><strong>The final answer</strong></p> <p>The answer was to change:</p> <pre><code>list=[NSMutableArray arrayWithArray:[self list].array]; </code></pre> <p>To:</p> <pre><code>list = [[NSMutableArray alloc] init]; </code></pre> <p>(...Which isn't really the best way to create an NSMutableArray, but it may work anyway.)</p> <p><strong>This was based on an erroneous version of the asker's code</strong></p> <p>Based on your comment that it crashes after <code>[list addObject:[self tem].array];</code>, I must conclude that your instance variable <code>list</code> is of type <code>Stack*</code>, and that Stack is not a subclass of NSMutableArray. If so, that's your issue.</p> <p>In that case, changing that line to <code>[[list array] addObject:[self tem].array];</code> should fix it.</p> <p><strong>This is just good advice</strong></p> <p>As an aside, NSMutable array is perfectly capable of acting as a stack without modification. Example:</p> <pre><code>NSMutableArray* ar = [NSMutableArray arrayWithCapacity:someCapacity]; // Push [ar addObject:narf]; // narf being some object reference // Pop id popped = [ar lastObject]; [ar removeLastObject]; </code></pre> <p>If you want to encapsulate stack behavior in a semantically consistent way, you can add push and pop methods to NSMutableArray using a category. This would make your code simpler and less prone to error.</p> <p><strong>This was my first stab at answering the question, before any code had been posted</strong></p> <p>This is a stab in the dark since you've not posted any code. BUT. One way to accomplish that with arrays is by creating arrays using <code>[NSArray arrayWithObjects:obj obj ... nil]</code> and omitting the nil terminator on the list of objects. Are you by any chance doing that?</p>
 

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