The implementation provided by the OP, in the other answer is incorrect, as it does not copy the instance variables; rather it creates another reference to them. This would explain the issues the OP is seeing in his question (where that code should have been presented, and not in a separate answer).
Here is a better implementation:
- (id)copyWithZone:(NSZone *)zone
{
Item *copy = [[Item allocWithZone:zone] init];
copy->_nombre: [_nombre copy];
copy->_linea = [_linea] copy];
copy->_tags = [_tags copy];
copy->_htmlSource = [_htmlSource copy];
return copy;
}
Note that the instance variable copy statements provided in the other implementation is correct (aside from the missing copy
call), but it won't work for private instance variables (a common occurrence), so I always stick to the form copy->_instanceVariable = [_instanceVariable copy];
.
Also note that if the object derives from something other than NSObject
then first statement should be:
Item *copy = [super copyWithZone:zone];
instead of:
Item *copy = [[Item allocWithZone:zone] init];
Further notes:
I find it highly suspect that you are keeping NSMutableString
objects as instance variables. That is fairly unusual in my experience, having only used them as temporary objects for building immutable strings. I suspect you are not using the correct data type to hold this data.