The wording of a single example in Swift

Source: Internet
Author: User

In Swift, a single case differs from OC in that it is written in many different ways, and if a. Swift file creates only one class, you can use that dispatch_once notation, If there are many classes in a. Swift file, an error will be made, and it needs to be written as below, so that the page is more simple

Declaring static properties at the bottom

1 static var resourcebundle:nsbundle?

Implemented in a function

1     //MARK:-------Weibo resource bundle--------2     classFunc bundle ()NSBundle3     {4         ifSelf.resourcebundle = =Nil {5Self.resourcebundle = NSBundle (Path:NSBundle.mainBundle (). Pathforresource ("Resourceweibo", OfType:"Bundle")!)!6         }7         returnself.resourcebundle!8}

This makes it very simple to implement a single example, even if the class is created repeatedly, and Singleton properties are only generated once

How to do a single example in Swift

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.