在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]'变得无效”根据什么无效? “类属性”声明声明该方法;事实上,它确实如此。 –