sharedInstance can be used in several ways.
For example, you can access an object from a static context. In fact, it is used by most ways to support the Singleton template. This means that only one class object is used in the entire program code, only one instance.
The interface might look like this:
@interface ARViewController { } @property (nonatomic, retain) NSString *ARName; + (ARViewController *) sharedInstance;
Implementation of ARViewController:
@implementation ARViewController static id _instance @synthesize ARName; ... - (id) init { if (_instance == nil) { _instance = [[super allocWithZone:nil] init]; } return _instance; } + (ARViewController *) sharedInstance { if (!_instance) { return [[ARViewController alloc] init]; } return _instance; }
To access it, use the following in the CustomARFunction class:
#import "ARViewController.h" @implementation CustomARFunction.m - (void) yourMethod { [ARViewController sharedInstance].ARName = @"New Name"; }
source share