How to create straight forward Singleton classes in Objective C? -
I am used for java
and currently it is written on Objective-C
.
Actually I will create java
in the singleton
sections:
public class singletonclass {personal stationary example; // Step 1 Public stable singleton class getInstance () {// Step 2 if (example == zero) Example = New Singleton (); Return example; }}
very straightforward?
But I find it a difficult time for which to make a straight forward solution in objective-c
I did this:
@implementation SingletonClass () {// Here I want to do step 1 which is to create a static example; // It is said that the private variable has been declared here; * SingletonClass * example; // is said that the stable keyword is different here} // so i have to do something like step 2 + (id) getInstance {if (example == zero) example = self; Return example; } @end
The problem is that there is an error: does not allow the type name to specify the storage class
Use sender_OCI_T
:
See also: By Mike Ash
+ (instancetype) Shared Instance {Static Dispatch_oncectic one time token; Sending & amp; (& amp; Once & # 39; Token, ^ {sharedInstance = [[SingletonClock] Init];}); Return Share Instance; }
Comments
Post a Comment