views:

78

answers:

1

Hello, having a strange issue, must be something I'm just not seeing.

I set up a variable in the .h

NSDate *checkIn;

@property (nonatomic, retain) NSDate *checkIn;

I'm setting a variable to todays date in the initWithNibName:

checkIn = [NSDate date];

I also did synthesized it as well. Now later on in my program I use it to build a tablecell with the following line

cell.textLabel.text = [dateFormatter stringFromDate:checkIn];

This line kills the simulator, BAD_EXEC. If I put in a checkIn = [NSDate date]; above it, it works fine. So I'm thinking the variable isn't being stored from when I set it in the initWithNibName:

Not sure why though, as my strings I do the same way are all working fine from method to method. What am I missing?

+2  A: 

Using

checkIn = [NSDate date];

is a direct assignment and therefore, is released during the autorelease phase.

You want to use your property by making use of dot notation.

self.checkIn = [NSDate date];

This is make use of the property attributes (specifically retain) and prevent the date to be released to 0.

MarkPowell
Thank you! This was it. Learn something new everyday. :)
John