static NSString generates compilation warnings
In a simple NSObject
subclass that conforms to NSCoding
protocol, I declare some static NSString
in my header file :
static NSString *MYCodingKey = @"myPropertyName";
...
I wonder why Xcode is generating so many warnings about the fact I declare but don't use it. I understand the warning since the subclass is imported in many files and I don't employ the key for something in each. But so, does it mean that my key is in some way 'redefined' each time I import the header ? Doesn't the #import
statement prevent the header from being included multiple times ? I surely don't have warning saying I've declared it multiple times.
I'm just ignoring these开发者_C百科 warnings at the time, but I would be glad to read a bit more on that.
Thank you.
Well the warning is because you have a variable declared but you're not using it. Essentially you're just wasting space in the programs data section with things you're never going to use. Some compilers will optimize it and actually remove it if the symbol is not used (not sure if gcc with objc flag does so).
精彩评论