I have a Swift class:
我有一个Swift类:
class MyTextField : NSObject, UITextFieldDelegate {
var myField: UITextField
// no idea how to pass in my UITextField from Objective-C code
init (x: UITextField) {
myField = x;
}
}
I have added a property (not shown) so I could set myField, and everything is working.
我添加了一个属性(未显示),因此我可以设置myField,一切正常。
Would like to use the init function, if only the syntax were not a complete mystery. Any ideas?
想使用init函数,如果只是语法不是一个完整的谜。有任何想法吗?
1 个解决方案
#1
9
Call it the same way you'd call an Obj-C initializer, so for your example, you'd call [[MyTextField alloc] initWithX:theTextField];
.
以与调用Obj-C初始化程序相同的方式调用它,因此对于您的示例,您将调用[[MyTextField alloc] initWithX:theTextField] ;.
#1
9
Call it the same way you'd call an Obj-C initializer, so for your example, you'd call [[MyTextField alloc] initWithX:theTextField];
.
以与调用Obj-C初始化程序相同的方式调用它,因此对于您的示例,您将调用[[MyTextField alloc] initWithX:theTextField] ;.