寫一個類 起作用是 傳值
#import
@interface singleton : NSObject
+(singleton *)shareData;
@property (strong, nonatomic) NSString *value;
@end
#import "singleton.h"
@implementation singleton
static singleton *singletonData = nil;
+(singleton *)shareData {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singletonData = [[singleton alloc] init];
});
return singletonData;
}
-(id)init {
if (self = [super init]) {
}
return self;
}
@end
singleton *oneS = [singleton shareData];
oneS.value = @"my name is caomao";
NSLog(@"oneS.value---->%@",oneS.value);
值已經賦好啦 。。。 在就是 在你所需要的類調用出 就OK 啦 這是在B類的調用NSString *strB = [singleton shareData].value];