//what is a single case? //A singleton is a single instance object that guarantees that the object, no matter how many times it is created, is the only//uiscreen uidevice Nsfilemanager nsuserdefaults /*system Singleton class: [UIScreen mainscreen] [uidevice currentdevice] [nsfilemanage Defaultmanager] [nsuse Rdefaults Standarduserdefaults]*/#pragmaMark —————————— the use of singleton classes ——————————The value of the first page is passed to the third page, and the following values are passed to the previous#pragmaMark —————————— the creation of a singleton class ——————————@interfaceHandler:nsobject//The singleton method is a class method, and the return value type is Instancetype//a singleton class that is defined by itself, and the method name usually begins with share@property (nonatomic, copy) NSString *string;+(instancetype) shareinstance;@end StaticHandler *handler =Nil;@implementationHandler//how to ensure that singleton objects are unique+(instancetype) shareinstance{@synchronized (self) {//Self This object is an arbitrary object that is locked to ensure that the creation process allows only one thread object to access at the same time if(Handler = =Nil) { //A singleton cannot be released, otherwise it cannot be guaranteed to be unique//and, under multiple threads, may be created multiple timesHandler =[[Handler alloc] init]; } } returnhandler;}@end#pragmaMark —————————— the use of a single case ——————————-(void) click{//Create a single caseHandler *handlder =[Handler shareinstance]; Handlder.string=_textfiled.text; Secondviewcontroller*second =[[Secondviewcontroller alloc] init]; [Self.navigationcontroller Pushviewcontroller:second Animated:yes]; [Second release];} //Create a single caseHandler *handlder =[Handler shareinstance]; Label.text= Handlder.string;
Contacts--Single case