Contacts--Single case

Source: Internet
Author: User

    //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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.