I've read up on "static" on several occasions, including just before posting this question. I'm still searching for an "Aha" though.
In the context of UITableView's static comes up in Cell Identifiers in every piece of code I've looked at. For example in a recent CellForRowAtIndexPath:
static NSString *defaultIndentifier = @"Managed Object Cell Identifier";
My question is why do we need and use "static"?
There's no real benefit here. It's mostly just a hint to the reader that the same value is used for all cells in this particular bit of code. As the identifier itself is a constant string, it gets compiled into an immutable chunk of memory and referenced as the same pointer every time, e.g. there is no cost involved in constructing the string even if you remove the static
keyword.
So that it will only be constructed once. If it's not static, you'll be making one every time the message is sent (which is a lot)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With