So I grab the username from the field, save it in an NSString variable:
loggedInUser = [usernameField stringValue];
[loginWindow close];
Later, I try to access that loggedInUser data:
NSLog(@"Logged in User:%@", loggedInUser);
This often, but not always, gives an error:
Program received signal: "EXC_BAD_ACCESS". // Summary displays "{...}" for the value
The loggedInUser NSString gets cleared? What happened? (I never modify this value myself).
My only thought is that I am somehow saving the continued value of the NSTextField in the NSString. Then, when I close the window, that value is cleared.
Is that what’s happening? How do I save that Textfield value in a safe way for continued use?
Ahhh, I just realized what is going on.
When you close your window (and it likely gets released), the string that you assigned to your object’s NSString variable is autoreleased as well.
You need to explicitly retain it.
Or, more to the point, do this:
or:
don’t forget to release
loggedInUserwhen yourdeallocmethod is called (assuming you’re not using ARC here).