Reputation:
Largely curious really. In the provided Apple UITableViewDataSource
method tableView:cellForRowAtIndexPath:
, the name given to the static NSString
variable used for the cell identifier is always capitalised, like so:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableViewCell"; // CAPITALISED VARIABLE NAME
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
// Configure cell
return cell;
}
Whilst I realise it makes no difference to the program when it runs, Objective-C naming conventions state that variables should have their first letter lower case and classes should have theirs uppercase. Why is this not the case here?
Upvotes: 4
Views: 628
Reputation: 3921
Capitalizing the first letter is used to denote that CellIdentifier is a constant.
Now, you may wonder, why can't you just do this...
static const NSString *cellIdentifier = @"TableViewCell";
The answer is because const does not work with NSString as the programmer would expect. The string value of NSString can still be changed even if it is marked as const, so the following series of expressions...
static const NSString *cellIdentifier = @"TableViewCell";
cellIdentifier = @"Changed!"
NSLog(@"%@", cellIdentifier);
Would log "Changed!" to the console, NOT "TableViewCell". Because of this, a capital letter is used to imply that CellIdentifier is a constant, although it can technically still be altered, it is just "not supposed" to be altered.
Upvotes: 3
Reputation: 11174
The cell identifier here is effectively a constant, which by convention are capitalised
Upvotes: 1