Import arc and MVC singleton patterns into the same header file

Source: Internet
Author: User

//. h file#defineHmsingletonh (name) + (instancetype) shared# #name;//. m file#if__has_feature (OBJC_ARC)#defineHMSINGLETONM (name)StaticID _instace; + (ID) Allocwithzone: (struct_nszone *) Zone {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instace=[Super Allocwithzone:zone];         }); return_instace; }      +(instancetype) shared# #name {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instace=[[Self alloc] init];         }); return_instace; }      -(ID) Copywithzone: (Nszone *) Zone {return_instace; }#else    #defineHMSINGLETONM (name)StaticID _instace; + (ID) Allocwithzone: (struct_nszone *) Zone {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instace=[Super Allocwithzone:zone];         }); return_instace; }      +(instancetype) shared# #name {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instace=[[Self alloc] init];         }); return_instace; }      -(ID) Copywithzone: (Nszone *) Zone {return_instace; }      -(OneWayvoid) Release {}-(ID) retain {returnSelf ;} -(Nsuinteger) Retaincount {return 1;} -(ID) autorelease {returnSelf ;}#endif

System comes with judgment condition statement

#if _has_feature (BBJC_ARC)

If it's Arc mode, implement the code inside

#else

If it is the MVC pattern, implement the code inside

#endif

Import arc and MVC singleton patterns into the same header file

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.