I completely understand that. How is it though when I call the default gameID getter my app crashes.
This doesn't appear to happen with another on of my objects however I haven't been able to find the issue. they appear to look the same.
Mike
My guess: your member/property name is "gameid" and you're sending the message "gameID" to try to get the member, which will cause a crash, as "gameid" != "gameID". If this is indeed what's happening, you should have gotten a "... may not respond to ..." compiler warning (which you should have addressed at the time).
Kalimba is also correct. My bet is that your problem is a combination of using the prefix "get" and the not using a consistent label for the ivar and the property. (It's hard to pick up your own typos in this kind of error -- read carefully). I'm also assuming that you are using @synthesize in your .m file. If all you are doing is returning the value of the ivar, I'd let the synthesize command handle the getter and not specify the getter at all in your code. So, use either:
//Needs to claim the ivar with the same label -- gameid
@synthesize gameid;
or
//getter on the property gameid
-(NSString *)gameid{
return gameid; //This is the ivar gameid claimed by the property gameid
}
I think you will get a crash when calling a nonexistent getter/setter (either by synthesize or explicit definition). You get a warning when calling a function that hasn't been defined in the header. Best I can tell, these are treated differently by the compiler.
I've had times where deleting what is there and starting over solves the problem -- either I'm more careful the second time or some phantom bug resolves. I don't argue with the success when this works. Good luck!
Kalimba is also correct. My bet is that your problem is a combination of using the prefix "get" and the not using a consistent label for the ivar and the property. (It's hard to pick up your own typos in this kind of error -- read carefully). I'm also assuming that you are using @synthesize in your .m file. If all you are doing is returning the value of the ivar, I'd let the synthesize command handle the getter and not specify the getter at all in your code. So, use either:
//Needs to claim the ivar with the same label -- gameid
@synthesize gameid;
or
//getter on the property gameid
-(NSString *)gameid{
return gameid; //This is the ivar gameid claimed by the property gameid
}
I think you will get a crash when calling a nonexistent getter/setter (either by synthesize or explicit definition). You get a warning when calling a function that hasn't been defined in the header. Best I can tell, these are treated differently by the compiler.
I've had times where deleting what is there and starting over solves the problem -- either I'm more careful the second time or some phantom bug resolves. I don't argue with the success when this works. Good luck!
I had posted some pseudo code so its possible I had a typo. When trying to use @synthesize gameId I get nothing in the console and the simulator/device closes. The only thing that I am doing currently (and not fully understanding) is using the AppDelegate to hold a NSMutableArray that holds the games. I then call something like appDelegate = (ProgramNameAppDelegate *)[[UIApplication sharedApplication] delegate];
I then use that variable like [[appDelegate.games objectAtIndex:0] gameId]; I know that its possible that it thinks that its not type-casted however if I change gameId to description I get the output that I want.
I might delete the files and start over again with that class.
If anything else pops in your minds, please send them my way.
Thanks for your help. I will post any fixes found.
When you want to pull info from the array in your app delegate, just message for the sharedApplication and not a second call to the delegate of that object. I would set a break point on the statement with the sharedApplication and step through until you get the crash. I wonder if your problem is that you are just not getting ahold of the object that you are then trying to get your property value from.
If it is a problem with the property, I would suggest that you use the dot syntax when working with properties. Besides being apparent in the code that you are working with properties, it keeps your mind in that space.
I'm not sure that you understand that gameid and gameID are different to the compiler (it is Case Sensitive). If you define the property as gameID and then call for it as gameid, you will get the kind of behavior that you mention.
Example: Let's go with gameID:
class.h
{
NSString *gameID;
}
@property (nonatomic, retain) NSString *gameID;
class.m
@synthesize gameID; //Don't do explicit methods unless you have a reason.
//If you have a reason, then do this
-(NSString *)gameID{
return gameID; //gameID and gameID match
}
//A sample function using the property you just set up
-(NSString *)idOfGame{
//retrieve the gameObject from your array
gameObject = ...;
return gameObject.gameID; //This should work
return gameObject.gameid; //This would crash
}
Set a breakpoint on the entry to the getter and step through to the crash. The first line you will see steps to the synthesize statement for gameID. The second it won't find an appropriate synthesize statement and it will crash.
When you want to pull info from the array in your app delegate, just message for the sharedApplication and not a second call to the delegate of that object. I would set a break point on the statement with the sharedApplication and step through until you get the crash. I wonder if your problem is that you are just not getting ahold of the object that you are then trying to get your property value from.
If it is a problem with the property, I would suggest that you use the dot syntax when working with properties. Besides being apparent in the code that you are working with properties, it keeps your mind in that space.
I'm not sure that you understand that gameid and gameID are different to the compiler (it is Case Sensitive). If you define the property as gameID and then call for it as gameid, you will get the kind of behavior that you mention.
Example: Let's go with gameID:
class.h
{
NSString *gameID;
}
@property (nonatomic, retain) NSString *gameID;
class.m
@synthesize gameID; //Don't do explicit methods unless you have a reason.
//If you have a reason, then do this
-(NSString *)gameID{
return gameID; //gameID and gameID match
}
//A sample function using the property you just set up
-(NSString *)idOfGame{
//retrieve the gameObject from your array
gameObject = ...;
return gameObject.gameID; //This should work
return gameObject.gameid; //This would crash
}
Set a breakpoint on the entry to the getter and step through to the crash. The first line you will see steps to the synthesize statement for gameID. The second it won't find an appropriate synthesize statement and it will crash.
Other than that, I'm out of ideas. Good luck.
Ok I found my issue (Well its working at least). In my classes initWithGameIdNSString *)_gameId GameNameNSString *)_gameName, i was assigning the values like this:
gameId = _gameId;
gameName = _gameName;
I then changed this to:
[self setGameId:_gameId];
[self setGameName:_gameName];
it appears to be working now.
Also you keep referring to the gameID vs gameid. I do know that to the compiler that they are different. I was trying not to use the synthesized getter as I thought it wasn't working.