2016-09-14 66 views
2

在Xcode 8中,Objective-C稍有变化。现在有类级别的属性。 例如,标头一个NSBundleXcode 8,禁用类级别属性

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

看,主束。现在它被宣布为property,但与class关键字。我认为它代表class level property。好。

向下滚动后,我发现这些代码。

#define NSLocalizedString(key, comment) \ 
     [NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:nil] 
#define NSLocalizedStringFromTable(key, tbl, comment) \ 
     [NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:(tbl)] 

看,如何mainBundle访问。但是我使用JetBrains中的AppCode,并且此IDE将这种结构视为无效代码。 AND,[NSBundle mainBundle]变为无效,AS+ (instancetype)mainBundle方法不存在。

我的问题是 我可以以某种方式切换到旧的ObjectiveC风格编码没有切换的Xcode?

+0

所以,你对的Xcode或AppCode问题? – Kreiri

+3

“'[NSBundle mainBundle]'变得无效”根据什么无效? “类属性”声明声明该方法;事实上,它确实如此。 –

回答

2

简短的回答:NO

但是,这仅仅是一个AppCode突出问题。代码应该仍然可以编译,它在语法分析器中被标记为错误。

按照youtrack问题,知道什么时候它会被固定:https://youtrack.jetbrains.com/issue/OC-14107

+1

已在最新的2016.3 EAP中修复。 –

7
@property (class, readonly, strong) NSBundle *mainBundle; 

这相当于(带有帮助的静态分析和斯威夫特API产生一些额外的元数据):

+ (NSBundle *)mainBundle; 

如果您的IDE /编译器,随后不正确编译[NSBundle mainBundle]等价(或在那里),那么你的IDE /编译器坏了。