Why are capital letters of table cell variable identifiers?

Mostly curious. In the Apple provided UITableViewDataSource method tableView:cellForRowAtIndexPath: name specified for the NSString static variable used for the cell identifier is always capitalized, for example:

 - (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TableViewCell"; // CAPITALISED VARIABLE NAME UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; // Configure cell return cell; } 

As long as I understand that it does not make any difference to the program when it starts, the Objective-C naming conventions indicate that variables should have their first case lowercase, and classes should have their upper case. Why is it wrong here?

+4
source share
2 answers

The first capital letter is used to indicate that the CellIdentifier is a constant.

Now you may wonder why you cannot just do this ...

 static const NSString *cellIdentifier = @"TableViewCell"; 

The answer is that const does not work with NSString, as the programmer expected. The NSString string value can be changed even if it is marked as const, so the following series of expressions ...

 static const NSString *cellIdentifier = @"TableViewCell"; cellIdentifier = @"Changed!" NSLog(@"%@", cellIdentifier); 

Will the magazine "Changed!" to the console, not "TableViewCell". Because of this, an uppercase letter is used to indicate that the CellIdentifier is a constant, although it is technically still possible to change, it is simply “not supposed” to change.

+3
source

The cell identifier here is actually a constant that, by convention, is capitalized.

+1
source

All Articles