I want to get UITextInputMode in Swift 2 but UITextInputMode.activeInputModes()
crashes.
let x = UITextInputMode.activeInputModes() // crash here
for t in x {
print(t)
}
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 <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
From Swift, you can now call Kludge.activeInputModes() and get the correct results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With