views:

34

answers:

2

Hi all. Can someone please explain to me why this simple assignment doesn't work.
Here is the code
loanDetails.currency = myCurrency;
NSLog(@" Value %@",myCurrency);
NSLog(@" Value %@",loanDetails.currency);
NSLog(@" Value %@",myCurrency);

the output is:-
2010-05-05 23:00:44.394 ExpenseTracker[3576:207] Value AFA
2010-05-05 23:00:44.750 ExpenseTracker[3576:207] Value (null)
2010-05-05 23:00:45.095 ExpenseTracker[3576:207] Value AFA

And the definition is as:

@property (nonatomic,retain) NSString *currency;

A: 

Well, when you write loanDetails.currency = myCurrency, that's the equivalent of calling [loanDetails setCurrency:myCurrency]. So, take a look at your header: did you define it readonly by accident? Have you synthesized accessor methods or did you write your own?

Jeff Kelley
I have added the definition to the question. It was readonly but then the compiler showed an error, so i changed it to the definition described above.
tak
+2  A: 

Is loadDetails nil?

MrHen
This is exactly the problem. I was never initializing it. But there was no exception at runtime. In java it would have been a NULL Pointer exception.
tak