在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?
所以,你對的Xcode或AppCode問題? – Kreiri
「'[NSBundle mainBundle]'變得無效」根據什麼無效? 「類屬性」聲明聲明該方法;事實上,它確實如此。 –