Ios 如何在Swift项目上使用键盘控件?

Ios 如何在Swift项目上使用键盘控件?,ios,objective-c,swift,Ios,Objective C,Swift,如何在swift项目上使用这个名为BSKeyboardControls的库 问题是我不知道如何转换这个部件 [self setKeyboardControls:[[BSKeyboardControls alloc] initWithFields:fields]]; [self.keyboardControls setDelegate:self]; 变成斯威夫特 如何解决这个问题? 谢谢 假设代码位于实现BSKeyboardControlsDelegate协议的视图控制器内,我们首先向视图控制

如何在swift项目上使用这个名为BSKeyboardControls的库

问题是我不知道如何转换这个部件

[self setKeyboardControls:[[BSKeyboardControls alloc] initWithFields:fields]];
[self.keyboardControls setDelegate:self];
变成斯威夫特

如何解决这个问题?
谢谢

假设代码位于实现
BSKeyboardControlsDelegate
协议的视图控制器内,我们首先向视图控制器添加
keyboardControls
属性,以保存对键盘控件的引用:

class SomeViewController: UIViewController, BSKeyboardControlsDelegate {

    var keyboardControls: BSKeyboardControls? // Here's our property

    // Remaining view controller code here...
}
(这是一个可选选项,后面带有问号,因为在我们设置它之前它将为零。)

然后,假设您有一个名为
fields
的数组,其中包含您正在使用的字段,我们可以将这两行转换为以下内容:

self.keyboardControls = BSKeyboardControls(fields: fields)
self.keyboardControls?.delegate = self