Xcode4 templates now use underscore on iVars?

I noticed that with Xcode4, Apple updated application templates to include underscores in front of instance variables.

// Xcode4 @property (nonatomic, retain) IBOutlet UIWindow *window; @synthesize window = _window; 

.

 // Xcode3 @property (nonatomic, retain) IBOutlet UIWindow *window; @synthesize window; 

I know that there are different opinions about the utility , but I was just wondering if the updated templates, where:

  • (1) Highlighting new best practices.
  • (2) Shows how Apple does something, but for you this means the old way.
  • (3) Its just a personal taste, it does not matter.
+3
source share
1 answer

Interestingly, in the past (pre-iOS), Apple used to prevent the use of underscore prefixes for ivars :

Avoid using the underscore as a prefix meaning private, especially in methods. Apple reserves the use of this agreement. Use by third parties may result in name collisions with spaces; they can unwittingly redefine the existing private method with one of their own, with disastrous consequences. See "Private Methods" for convention proposals for a private API.

But with the modern version of Objective-C, I believe that ivar ivar name conflicts in subclasses have been resolved, so this is no longer a problem. Therefore, I think that why templates use the default underscore prefix to match Apple's internal code.

+6
source

Source: https://habr.com/ru/post/908189/


All Articles