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:
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论