Я новичок в Objective-C, и я искал и читал здесь несколько постов о том, как создать "глобальную переменную", но я просто не могу заставить ее работать правильно, пока я могу ее создать и проверить, нозначения не сохраняются в других представлениях, моя глобальная переменная представляет собой массив пользовательских объектов с именем «профиль», я хотел бы иметь возможность читать и записывать этот массив из любого представления моего приложения для iphone (делегат tabbarapplication);
Helper.h
@interface Helper : NSObject {
int globalInteger;
NSMutableArray *profiles;
}
@property (nonatomic, retain) NSMutableArray *profiles;
// message from which our instance is obtained
+ (Helper *)sharedInstance;
Helper.m
#import "Helper.h"
@implementation Helper
@synthesize profiles, globalInteger;
+ (Helper *)sharedInstance
{
// the instance of this class is stored here
static Helper *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;
}
ACertainViewController.m
//Initialize Policies Array
NSMutableArray *profs = [[Helper instance] profiles];
profs = [[NSMutableArray alloc] init];
//Sample Data
Profile *prof1 = [[Profile alloc] init];
prof1.name = @"John";
//add
[profs addObject:prof1];
[[[Helper instance] profiles] addObject:prof1];
После этой точки, если я проверю глобальныйсодержимое var "profile" снова возвращает count == 0;Что касается globalInteger var, я даже не знаю, как установить его значение для возможности чтения в другом месте приложения.Любая помощь высоко ценится!Спасибо !!!