2016-09-14 17 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는 이런 구조를 잘못된 코드로 취급합니다. , [NSBundle mainBundle]은 유효하지 않습니다. + (instancetype)mainBundle 메서드가 존재하지 않습니다.

내 질문에 가 어떻게 든 엑스 코드를 전환없이 기존 오브젝티브 -c 스타일의 코딩 로 전환 할 수 있습니다인가? 당신의 IDE/컴파일러 이후 제대로 [NSBundle mainBundle]를 컴파일하지 않는 경우

+ (NSBundle *)mainBundle; 

(또는 동등 (정적 분석기와 스위프트 API 생성하는 데 도움이 몇 가지 추가 메타 데이터)이 동일하다

+0

그래서 엑스 코드 또는 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; 

IDE/컴파일러가 깨졌습니다.