Pergunta

I am trying to add an object to an NSMutableArray taskArray. The object is an instance of taskClass called emptyTask. When I create emptyTask and try to add it to myDelegate, I get following error: 'NSInvalidArgumentException', reason: '-[TaskClass copyWithZone:]: unrecognized selector sent to instance 0x8c63f10

myDelegate = [UIApplication sharedApplication].delegate;
myDelegate.taskArray = [[NSMutableArray alloc]init];
TaskClass* emptyTask = [[TaskClass alloc]init];
emptyTask = [emptyTask starterTaskClass];
[myDelegate.taskArray addObject:emptyTask];

I can replace emptyTask with an NSString and it adds to myDelegate. I can also add emptyTask to a locally created NSMutableArray and it works. So it seems it has something to do with my class to myDelegate. I have #import "TaskClass" in all of my header files.

Thoughts?

Foi útil?

Solução

Something is trying to copy your delegate somewhere down the line, either directly or (more likely) using it as the key in a dictionary. You have a couple options

  • Figure out where and change it to not copy/use a dictionary; or
  • Implement -[TaskClass copyWithZone:]; as long as you're doing that you may as well declare yourself to conform to the NSCopying protocol.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top