nonamorando
nonamorando

Reputation: 1605

Is it preferable to use a static string with a cell identifier?

Currently am diving into the iOS/Objective-C world and was curious if there are benefits to using a static string as a cell identifier rather than just a written string.

Static Example:

static NSString *CellId = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];

Written Example:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];

Could anyone elaborate on the differences and perhaps then, the reasons of using one over the other?

Upvotes: 1

Views: 196

Answers (2)

mipadi
mipadi

Reputation: 410922

Not really -- either way, it will only be stored in memory once. Do whatever makes the most sense to you and your code. (Personally, I'd use the static variable if I were going to refer to the cell identifier in more than once place, and a string literal otherwise.)

Upvotes: 1

Will M.
Will M.

Reputation: 1854

One reason why you might use a static string is if you will use the identifier in multiple places, you can have it written in one place, and then it is easy and safe to change (change once and it propagates everywhere it is used).

Upvotes: 2

Related Questions