Note that there are some explanatory texts on larger screens.

plurals
  1. POIsEqual Method Sent to Deallocated Instance When Trying to Add Object To MutableOrderedSet
    text
    copied!<p>I have an NSMutableOrdered set that holds two types of objects (that I created), Pieces and Others.</p> <p>Piece and Other both have their isEqual method overridden like so:</p> <p>Piece:</p> <pre><code>- (BOOL)isEqual:(Piece *)object { if (([title isEqualToString:[object title]]) &amp;&amp; ([composer isEqualToString:[object composer]]) &amp;&amp; (major == [object major]) &amp;&amp; (tempo == [object tempo]) &amp;&amp; (pieceKey == [object pieceKey]) &amp;&amp; (pieceTime == [object pieceTime])) return YES; else return NO; } </code></pre> <p>Other:</p> <pre><code>- (BOOL)isEqual:(Other *)object { if (([title isEqualToString:[object title]]) &amp;&amp; ([subTitle isEqualToString:[object subTitle]]) &amp;&amp; ([description isEqualToString:[object description]]) &amp;&amp; (otherTime == [object otherTime])) return YES; else return NO; } </code></pre> <p>I also override the hash of both classes to create a unique hash for each instance (by getting the int value of the ivars and adding them).</p> <p>In my app, An Other is removed from the set, then when I try to add a piece to the set, I get this:</p> <pre><code>-[Other isEqual:]: message sent to deallocated instance 0x80d5680 </code></pre> <p>here is the hash method:</p> <pre><code>- (NSUInteger)hash { NSUInteger prime = 31; NSUInteger result = 1; result = prime * (result + [title intValue]); result = prime * (result + [composer intValue]); result = prime * (result + major); result = prime * (result + tempo); result = prime * (result + pieceKey); result = prime * (result + pieceTime); return result; } </code></pre> <p>If anybody knows why this is happening, I would really some help.</p> <p>Thanks,</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