Nir Gaiger Nir Gaiger - 2 months ago 5x
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:@""];
//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?


Try this:

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