我创建了一个单例 class,如何从我的 ViewController 调用它?

I've created a singleton class, how can I call it from my ViewControllers?

我已经创建了以下单例 class,但我不确定如何从我的 ViewController 中调用它(抱歉这个新问题)?我已经将它导入我的 ViewController (#import cloudStore.h),但是我应该在 ViewController 的 viewDidLoad 中使用哪一行代码才能 "use" 它?

cloudStore.h

#import <Foundation/Foundation.h>

@interface cloudStore : NSObject

+(cloudStore *)singleton;

@end

cloudStore.m

#import "cloudStore.h"

@implementation cloudStore

+(cloudStore *)singleton {
    static dispatch_once_t pred;
    static cloudStore *shared = nil;
    dispatch_once(&pred, ^{
        shared = [[cloudStore alloc] init];
    });
    return shared;
}

@end

你应该做

cloudStore *aCloudStore = [cloudStore singleton];

为了获得对您的单个 cloudStore 实例的引用。