我想在 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
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
现在,您可以在 Swift 中调用 Kludge.activeInputModes() 并获得正确的结果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)