assign property behaves differently from simple instance variable???
assign property behaves differently from simple instance variable???
- Subject: assign property behaves differently from simple instance variable???
- From: Matt Neuburg <email@hidden>
- Date: Mon, 13 Dec 2010 11:01:39 -0800
I have reduced this problem (after losing an entire day of work, of course) to a very few lines of code. They won't make much sense but just bear with me. Here we go...
I have this code (iOS), and it works fine:
@interface TextFieldFunViewController : UIViewController {
UIView* firstResponder;
}
//@property (nonatomic, assign) UIView* firstResponder;
@end
@implementation TextFieldFunViewController
//@synthesize firstResponder;
- (void)textFieldDidBeginEditing:(UITextField *)tf {
self->firstResponder = tf;
}
- (BOOL)textFieldShouldReturn: (UITextField*) tf {
[tf resignFirstResponder];
return NO;
}
@end
Notice that I'm not *doing* anything with my ivar firstResponder. The code works: I tap in my text field, and the keyboard appears; then I tap Return and the keyboard vanishes. I can do this repeatedly until the cows come home.
Now I'll change the code so that firstResponder is backed by a property with a synthesized accessor - just uncomment the two commented lines in the above. This change breaks the project! I tap in my text field, the keyboard appears; I tap Return and the keyboard vanishes; and the text field becomes completely unresponsive forever after that.
How can this seemingly minor change make such a big difference? I'm not even *using* the synthesized accessor! Yet its mere presence breaks the project. How can this be? m.
PS A new discovery: changing the name of the ivar / property to "fr" solves the problem. So it appears that the problem is that I'm synthesizing accessors for the *name* "firstResponder". It is as if this name was being used under the hood in some way I'm unaware of, and synthesizing an accessor breaks its use. But how can *that* be?
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden