I want to get UITextInputMode in Swift 2 but UITextInputMode.activeInputModes()
crashes.
let x = UITextInputMode.activeInputModes() // crash
I was able to work around this bug by using an Objective-C bridge.
Bridge.h
#ifndef Bridge_h
#define Bridge_h
#import "Kludge.h"
#endif
Kludge.h
#ifndef Kludge_h
#define Kludge_h
#import
@interface Kludge : NSObject
+ (NSArray *)activeInputModes;
@end
#endif
Kludge.m
#import "Kludge.h"
@implementation Kludge
+ (NSArray *)activeInputModes {
return (NSArray *)[UITextInputMode activeInputModes];
}
@end
From Swift, you can now call Kludge.activeInputModes() and get the correct results.