Proper location of "static" values in class files?

Personally I've always put statics above any class implementations:


static NSString *const glop = @"glop";
@implementation Foo


However, I often see people use


@implementation Foo
static NSString *const glop = @"glop";


As a test I wrote a class extension and found (unsurprisingly) that this latter case does not enclose the static within the implementation - any class extension can see it as well as a function placed below the class implementation.


Is there some reason I'm unaware of to pu the static inside the implementation? I just find it ugly (but I know, everyone has a style opinion!)


David

Replies

As far as I know this is a style thing. Like you, I’ve seen both styles used. I don’t have a strong opinion as to which is better (then again I do most of my work in Swift these days, so the whole question is kinda moot to me).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Again, the big problem I have with the latter case is that to a naive reader, it implies the variable is scoped when its actually not. The issue is even more incideous when you use a non-static. I just put this in a class implementation:


NSString *fooper = @"Glop";


then in another class declared fooper extern and set it. Builds without error.


Anyway, was just wondering if I had missed something.