首页 > 代码库 > iOS 单例传值
iOS 单例传值
写一个类 起作用是 传值
#import <Foundation/Foundation.h>
@interface singleton : NSObject
+(singleton *)shareData;
@property (strong, nonatomic) NSString *value;
@end
#import "singleton.h"
@implementation singleton
static singleton *singletonData = http://www.mamicode.com/nil;
+(singleton *)shareData {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singletonData = http://www.mamicode.com/[[singleton alloc] init];
});
return singletonData;
}
-(id)init {
if (self = [super init]) {
}
return self;
}
@end
singleton *oneS = [singleton shareData];
oneS.value = http://www.mamicode.com/@"my name is caomao";
NSLog(@"oneS.value---->%@",oneS.value);
值已经赋好啦 。。。NSString *strB = [singleton shareData].value];
iOS 单例传值