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는 이런 구조를 잘못된 코드로 취급합니다. 및, [NSBundle mainBundle]
은 유효하지 않습니다. + (instancetype)mainBundle
메서드가 존재하지 않습니다.
내 질문에 가 어떻게 든 엑스 코드를 전환없이 기존 오브젝티브 -c 스타일의 코딩 로 전환 할 수 있습니다인가? 당신의 IDE/컴파일러 이후 제대로 [NSBundle mainBundle]
를 컴파일하지 않는 경우
+ (NSBundle *)mainBundle;
(또는 동등 (정적 분석기와 스위프트 API 생성하는 데 도움이 몇 가지 추가 메타 데이터)이 동일하다
그래서 엑스 코드 또는 AppCode 대한 질문은? – Kreiri
"'[NSBundle mainBundle]'무효가됩니다"무엇에 따라 무효입니까? "클래스 속성"선언은 해당 메소드를 선언합니다. 사실 그것은 그것이 사실입니다. –