2015-09-21 70 views

回答

5

這是Xcode 7中的一個bug,如HERE所述。這表示:

總結:

此前的Xcode 7 GM,UITextInputMode.activeInputModes()返回 UITextInputMode實例的數組。但是,在Xcode 7 GM中,頭文件和文檔中的方法簽名 指出它返回一個字符串數組,它不正確。因此,使用activeInputModes的代碼 正確地不再編譯,並且 嘗試在Playground中使用activeInputModes會引發 異常。

+0

感謝您的幫助! :) – aotian16

+0

快樂的幫助.. :) –

+0

可悲的是,這仍然在Xcode 7.1/iOS 9.1中損壞。 – rmaddy

10

我能夠通過使用Objective-C橋來解決這個bug。

Bridge.h

#ifndef Bridge_h 
#define Bridge_h 

#import "Kludge.h" 

#endif 

Kludge.h

#ifndef Kludge_h 
#define Kludge_h 

#import <UIKit/UITextInput.h> 

@interface Kludge : NSObject 

+ (NSArray<UITextInputMode *> *)activeInputModes; 

@end 

#endif 

Kludge.m

#import "Kludge.h" 

@implementation Kludge 

+ (NSArray<UITextInputMode *> *)activeInputModes { 
    return (NSArray<UITextInputMode *> *)[UITextInputMode activeInputModes]; 
} 

@end 

從斯威夫特,你現在可以調用Kludge.activeInputModes(),並得到正確的結果。

+0

這真是個好主意。我嘗試這個並且工作正常。你能否也看到我的另一個問題[如何檢測應用程序使用不是系統IME鍵盤在迅速](http://stackoverflow.com/questions/32706996/how-to-detect-if-app-use-not-system- ime-keyboard-in-swift) – aotian16

+0

謝謝!!!!!!!!!! – Luda

+0

非常聰明。希望蘋果將盡快解決這個問題。 –