Nir Gaiger Nir Gaiger - 3 months ago 11
iOS Question

'EXC_BAD_ACCESS code=2' Error happens when trying to set an object from a VC to another one

Let's say I have a 2 ViewController: A and B.

Here is some code of A:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
CategoryVC *vc = [storyboard instantiateViewControllerWithIdentifier:@"categoryVC"];
PParser *destPP = [[PParser alloc] init];
[destPP initWithFullURL:@"http://someurl.com"];
//setPp gives the Error EXC_BAD_ACCESS
[vc setPp:destPP];
SWRevealViewControllerSeguePushController *segue = [[SWRevealViewControllerSeguePushController alloc] initWithIdentifier:@"ANY_ID" source:self destination:vc];
[segue perform];


Here is some code of B:

-(void)setPp:(PParser *)pp{
self.pp = pp;
}


I guess this error has to do with the pointer which is not set correctly?Why do I get this error, and how should I fix it?

Answer

Try this:

-(void)setPp:(PParser *)pp  
{
  _pp = pp;
}
Comments