Reputation: 664
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?
Upvotes: 2
Views: 1064
Reputation: 2171
Short answer: NO
But this is simply an AppCode highlighting issue. The code should still compile fine, it's juste marked as an error in the syntax analyzer.
Follow the youtrack issue to know when it'll be fixed: https://youtrack.jetbrains.com/issue/OC-14107
Upvotes: 2
Reputation: 162722
@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.
Upvotes: 7