Create a ticket manually and manually

Source: Internet
Author: User

Create a ticket manually and manually

The so-called Singleton is: an application (app) has only one instantiated object, which is a singleton. It is generally used for music players and tools.

Here we will teach you how to manually create a singleton. One is to use mutex lock, and the other is to use dispatch for one-time execution.

 

1 // create a singleton 2 + (instancetype) sharedNetWorkTools 3 {4/static modify 5 static NetworkTools * tools = nil; 6 // determine whether the instantiated object exists 7 // mutex lock 8 @ synchronized (self) {9 if (tools = nil) {10 tools = [NetworkTools new]; 11} 12} 13 return tools; 14}

 

15 // create a singleton 16 + (instancetype) sharedNetWorkToolsOnce17 {18 // static modifier 19 static NetworkTools * tools = nil; 20 21 // One-time execution thread security 22 static dispatch_once_t onceToken; 23 dispatch_once (& onceToken, ^ {24 if (! Tools) {25 tools = [[NetworkTools alloc] init]; 26} 27}); 28 return tools; 29 30}

 

Related Article

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.