EDIT: This question applies to normal declared properties as well (not only to class properties)!
Original Post:
Lets say I have the public class method sharedInstance
which is currently implemented as a getter method:
@interface MyClass
+ (instancetype)sharedInstance;
- (void)doSomething;
@end
@implementation MyClass
+ (instancetype)sharedInstance {
static MyClass *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[MyClass alloc] init];
});
return shared;
}
@end
Accessing this method in Swift 3.0 would look like this: MyClass.shared().doSomething()
So to make it more swifty we should change the class method to a class property (new in Xcode 8. but actually I can't find it in the Apple Docu, only in WWDC 2016 video)
@interface MyClass
@property (class, nonatomic, readonly) MyClass *sharedInstance;
- (void)doSomething;
@end
// implementation stays the same
Now in Swift code: MyClass.shared.doSomething()
So does nonatomic/atomic
property modifier (don't know the exact term) even makes sense for a getter method which I implement myself in objc?