這裏是你如何定義被稱爲AppShareData單例類: AppShareData.h
@interface AppSharedData : NSObject
+(AppSharedData*)sharedInstance ;
@property (nonatomic) BOOL sharedBoolVariable ;
@end
AppShareData.m:
@implementation AppSharedData
@synthesize sharedBoolVariable;
+(AppSharedData *) sharedInstance
{
static AppSharedData *_sharedInstance = nil;
static dispatch_once_t Token;
dispatch_once(&Token, ^{
_sharedInstance = [[AppSharedData alloc]init];
});
return _sharedInstance;
}
@end
,然後如果你要編輯或設置的值的任何一類變量我會做以下幾點:
-(void)editMethod
{
AppSharedData * dataObject = [AppSharedData sharedInstance] ;
dataObject = YES ;
}
和如果我想檢索任何類變量的值,我做到以下幾點:
-(void)retrieveMethod
{
AppSharedData * dataObject = [AppSharedData sharedInstance] ;
BOOL someVariableInMyClass = [dataObject sharedBoolVariable] ;
}
你是怎麼看VC2的? – Misha
如果任何的答案幫助你,請投票或標記爲答案。 –
ArtusOlszak給出了正確的答案,但你真的應該花一些時間閱讀這個:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/ –