4

Swift 2 で UITextInputMode を取得したいのですが、UITextInputMode.activeInputModes()クラッシュします。

    let x = UITextInputMode.activeInputModes() // crash here

    for t in x {
        print(t)
    }
4

2 に答える 2

10

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() を呼び出して正しい結果を取得できるようになりました。

于 2015-09-22T03:51:55.930 に答える