Question

Having a problem with the following code (using xcode 5 with ios 7.1)

Player *aPlayer = theDungeon.thePlayer;
int r = aPlayer.lampRed;
int g = aPlayer.lampGreen;
int b = aPlayer.lampBlue;

Player *aPlayer = theDungeon.thePlayer;

returns a valid Player object which has each of the properties shows above and hovering over this variable and expanding it, I can see lampRed etc. just fine.

int r = aPlayer.lampRed;

At this line I get the bad access error.

This is the property:

  @property int lampRed;

Any idea why?

Was it helpful?

Solution

The EXC_BAD_ACCESS appears when an object is not initialized or an object is already released.

So I think that you are not initialized the object correctly and you are trying to access a property of him.

You have to instantiate the object:

Player *aPlayer = [[Player alloc]init];

then u can access to his property's

Use:

@property(nonatomic, assign) int lampRed;

instead

@property int lampRed;

On the other hand, and this is very important, you have to use the property in .m file:

@synthesize lampRed;

With this you obtain the getters and setters, otherwise not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top