2

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?

GRiMe2D
  • 654
  • 1
  • 10
  • 22
  • So is your question about Xcode or AppCode? – Kreiri Sep 14 '16 at 13:55
  • 3
    "`[NSBundle mainBundle]` becomes invalid" Invalid according to what? The "class property" declaration declares that method; that's in fact _all_ that it does. – jscs Sep 14 '16 at 18:16

2 Answers2

7
@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.

bbum
  • 162,346
  • 23
  • 271
  • 359
2

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