On Dec 29, 2011, at 3:38 PM, Peter Teeson wrote: > I'm familiarizing myself with Xcode 4.2.1 under Lion 10.7.2 so am doing the > "Your First Mac App" tutorial. > > This code snippet from the tutorial is incorrect and causes an error in > compilation. > if (sender == textField) { senderName = @"textField"; }……. > The error is "Use of undeclared identifier 'textField'; did you mean > _textField?" > > The correct code is: > if (sender == self.textField){senderName = @"textField"; } > > In fact if you refer to any of the synthesized iVars such as 'window' or > 'slider' > or indeed any that you care to make up for yourself (eg aardvark) the same > issue occurs. > > I don't know if this is a scope, language or compiler issue. > Why would one need to use self.textField?
This is just an issue with the tutorial. Those properties are @synthesized with an explicit instance variable name, which is different from the property name due to the underscore prefix: @synthesize textField = _textField; You don't necessarily have to refer to "self.textField". You could have changed that line to be: if (sender == _textField){senderName = @"textField"; } The problem with the original is that it referred to an identifier "textField" which didn't correspond to any declared variable. The instance variable is called "_textField". And property names are not accessible just as naked identifiers; they need to be accessed using Dot Syntax (or, of course, using the getter or setter names or Key-Value Coding). It was good of you to give that feedback to the document maintainers. Cheers, Ken _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com