@interface Connections()
{
static Connections *this;
}
@end
The above piece of code in .m file throwing compiler error
Type name does not allow storage class to be specified
at the same time when the
static
key word is removed it works well – which so obvious.
Purpose : I want “Connections” instance static and private.
Why is this behavior, please help.
You cannot declare class-level variables in Objective-C classes; instead you need to “hide” them in the implementation file, often giving them
static-scope so they cannot be accessed externally.Connections.m:
And if this is a singleton, you typically define a class-level accessor to create the singleton upon first use:
(and you’ll need to add the declaration in the .h file):