In Xcode 8, Objective-C slightly changed. Now there's class level properties. For example, headers for NSBundle
@interface NSBundle : NSObject {
...
/* Methods for creating or retrieving bundle instances. */
#if FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST(8)
@property (class, readonly, strong) NSBundle *mainBundle;
#endif
+ (nullable instancetype)bundleWithPath:(NSString *)path;
- (nullable instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
+ (nullable instancetype)bundleWithURL:(NSURL *)url NS_AVAILABLE(10_6, 4_0);
- (nullable instancetype)initWithURL:(NSURL *)url NS_AVAILABLE(10_6, 4_0);
+ (NSBundle *)bundleForClass:(Class)aClass;
+ (nullable NSBundle *)bundleWithIdentifier:(NSString *)identifier;
#if FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST(8)
@property (class, readonly, copy) NSArray<NSBundle *> *allBundles;
@property (class, readonly, copy) NSArray<NSBundle *> *allFrameworks;
#endif
...
Look at, main bundle. Now it is declared as property but with class keyword. I think it stands for class level property. OK.
After scrolling down I found these codes.
#define NSLocalizedString(key, comment) \
[NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:nil]
#define NSLocalizedStringFromTable(key, tbl, comment) \
[NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:(tbl)]
Look at, how mainBundle is accessed. But I use AppCode from JetBrains and this IDE treats constructions like this as invalid code. AND, [NSBundle mainBundle] becomes invalid, AS + (instancetype)mainBundle method doesn't exist.
MY QUESTION IS Can I somehow switch to old ObjectiveC style coding without switching Xcode?
@property (class, readonly, strong) NSBundle *mainBundle;
That is equivalent to this (with some additional metadata that helps the static analyzer and Swift API generation):
+ (NSBundle *)mainBundle;
If your IDE/compiler is subsequently not compiling [NSBundle mainBundle] correctly (or the equivalent therein), then your IDE/compiler is broken.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With