55231

Is there 2 methods for declaring instance variables in Objective C?

Question:

In most tutorials, the way to declare instance variable is to put it in .h

@interface myViewController: UIViewController { UITextField *myTextField; } @property (nonatomic, retain) IBOutlet UITextField *myTextField;

and in .m

@implementation myViewController @synthetize myTextField;

But in this standford University course <a href="http://itunes.apple.com/itunes-u/ipad-iphone-application-development/id480479762" rel="nofollow">http://itunes.apple.com/itunes-u/ipad-iphone-application-development/id480479762</a> the way to do so is rather

In .h do only:

@interface myViewController: UIViewController @property (nonatomic, retain) IBOutlet UITextField *myTextField;

In .m do this:

@synthetize myTextField = _myTextField;

Are they equivalent ? Is the second method specific to iOS5 ?

Answer1:

They are functionally equivalent. In ObjC 2.0 the synthesize keyword will automatically create the associated ivar if you do not specify one as part of the synthesize statement. This functionality is present on all modern runtimes.

Answer2:

They both work the same way, in the last one you actually have an instance variable named _myTextField. I don't know when this "feature" started, and would be interesting to know if the variable is inserted by the compiler or pre-compiler...

Answer3:

diffrence exist, in first variant you can see value of param in debugger in second variant you can't see value of param in debug mode

Recommend

  • Can Google GDK Glass Development Kit used with Vuzix glasses?
  • Add geocode long / lat to input field with event listener
  • Using image for webkit scrollbar - minimum height for -webkit-scrollbar-track-piece?
  • Back button breaks page in Chrome
  • How do I get a script to load before masonry?
  • using flyway to patch multiple identical schemas
  • Can't set focus to input in chrome extension
  • Embed image to email message in System.Web.Mail.MailMessage
  • Scrolling through div with JavaScript
  • Prevent date and time insert to the database
  • JSON and Highcharts
  • Appcelerator Titanium: CSS width won't work with percentages
  • How to solve Bad Request (#400) Unable to verify your data submission in yii2?
  • UPDATE Code causing Error, but it looks fine to me:
  • Form to perform action and passover the values
  • HTML editor for iOS [closed]
  • IE9: Force IE9 browser mode and document mode
  • Unity iOS Build size is way big
  • Core Data and iTunes File Sharing - Move/hide the .sqlite file on app update?
  • How to properly fetch single cells in pandas: loc[index,column] VS get_value(index,column)
  • Javascript snippet not working (missing lib?)
  • iOS - How to access the device's file library?
  • Jquery Google Maps V3 - Information window is always fixed to one marker
  • How to center a menu using flexbox [closed]
  • reduce/reduce conflicts using ocamlyacc
  • Open an application in a space using applescripts
  • Why does Sencha 2 only work in Webkit browsers?
  • retrieving data from url in iphone
  • how to populate a SQLite database and use that database in phonegap?
  • Access user's phone number on iOS 7
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • UIAlertController button function not working
  • Atlas images wrong size on iPad iOS 9
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • Turn off referential integrity in Derby? is it possible?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy