В ответ на вопрос о том, есть ли другие варианты (и не говоря уже о том, нужно ли это делать).Один из вариантов - сделать класс специально для хранения переменных, которые вам нужны для глобального доступа.Один пример из этого сообщения в блоге
@interface VariableStore : NSObject
{
// Place any "global" variables here
}
// message from which our instance is obtained
+ (VariableStore *)sharedInstance;
@end
@implementation VariableStore
+ (VariableStore *)sharedInstance
{
// the instance of this class is stored here
static VariableStore *myInstance = nil;
// check to see if an instance already exists
if (nil == myInstance) {
myInstance = [[[self class] alloc] init];
// initialize variables here
}
// return the instance of this class
return myInstance;
}
@end
Затем из других мест:
[[VariableStore sharedInstance] variableName]
Конечно, если вам не нравится, как они создают экземпляр синглтонаВ приведенном выше примере вы можете выбрать свой любимый шаблон здесь .Мне нравится сама модель dispatch_once.