Swift 2 で UITextInputMode を取得したいのですが、UITextInputMode.activeInputModes()クラッシュします。
let x = UITextInputMode.activeInputModes() // crash here
for t in x {
print(t)
}
Swift 2 で UITextInputMode を取得したいのですが、UITextInputMode.activeInputModes()クラッシュします。
let x = UITextInputMode.activeInputModes() // crash here
for t in x {
print(t)
}
Objective-C ブリッジを使用することで、このバグを回避することができました。
Bridge.h
#ifndef Bridge_h
#define Bridge_h
#import "Kludge.h"
#endif
クルージ.h
#ifndef Kludge_h
#define Kludge_h
#import <UIKit/UITextInput.h>
@interface Kludge : NSObject
+ (NSArray<UITextInputMode *> *)activeInputModes;
@end
#endif
クルージ.m
#import "Kludge.h"
@implementation Kludge
+ (NSArray<UITextInputMode *> *)activeInputModes {
return (NSArray<UITextInputMode *> *)[UITextInputMode activeInputModes];
}
@end
Swift から、Kludge.activeInputModes() を呼び出して正しい結果を取得できるようになりました。