How to call Swift initializer (with parameter) from Objective-C?

I have a Swift class:

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 added a property (not shown) to set myField and everything works.

I would like to use the init function if only the syntax were not a complete mystery. Any ideas?

+8
ios objective-c swift
source share
1 answer

Name it the same as you would call the Obj-C initializer, so for your example, you would call [[MyTextField alloc] initWithX:theTextField]; .

+9
source share

All Articles