Pass a value for a single example in iOS
To write a class, the function is to pass the value.
# Import
@ Interface singleton: NSObject
+ (Singleton *) parse data;
@ Property (strong, nonatomic) NSString * value;
@ End
# Import "singleton. h"
@ Implementation singleton
Static singleton * singletonData = nil;
+ (Singleton *) Upload data {
Static dispatch_once_t onceToken;
Dispatch_once (& onceToken, ^ {
SingletonData = [[singleton alloc] init];
});
Return singletonData;
}
-(Id) init {
If (self = [super init]) {
}
Return self;
}
@ End
If you want to pass the Value from A to B, you need to assign the Value to the Value.
Singleton * oneS = [singleton upload data];
OneS. value = @ "my name is caomao ";
NSLog (@ "oneS. value ----> % @", oneS. value );
The value has been assigned... In the class that you need, the call is OK. This is in the Class B call.
NSString * strB = [singleton upload data]. value];