Are there any Objective-C / Cocoa naming conventions for properties that are acronyms?
I have an object that models an online resource. Therefore, my object has to store the URL of the resource it belongs to. How would I name the getter and setter?
MyObject *myObject = [[MyObject alloc] init];
// Set values
[myObject setURL:url];
myObject.URL = url;
// Get values
[myObject URL];
myObject.URL;
or would the following be better:
MyObject *myObject = [[MyObject alloc] init];
// Set values
[myO开发者_高级运维bject setUrl:url];
myObject.url = url;
// Get values
[myObject url];
myObject.url;
The former example would of course require to define the property in the following way:
@property (retain, getter = URL, setter = setURL:) NSURL *url;
Apple has a list of Acceptable Abbreviations and Acronyms, where URL
is listed. I use URL
myself, consistent with NSURLRequest
, NSURLResponse
, NSPersistentStore
etc (which all have a URL
property).
I think an advantage to using uppercase names is that it works better with camelcase: anURL
looks better than anUrl
(in my opinion).
apple uses... both ;)
it looks like the pattern is moving towards url
/setURL:
精彩评论