I'm trying to create int object variable in singleton class. This my ObjC version:
+(MyClass*) single
{
static MyClass *shareObject = nil;
static dispatch_once_t onceToken;
dispatch_once ( &onceToken, ^{
shareObject = [[self alloc] init];
shareObject.myArray = [NSMutableArray new];
});
return shareObject;
}
Swift version:
class MyClass {
static let sharedInstance = MyClass()
var myArray = Array<Any>()
}
In case of the ObjC version I know myArray is init once. But my question to you guys in case of the Swift version. Does the myArray variable would be init once?