2016-09-14 41 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 /編譯器壞了。