I want to access swift class(variables and methods) in my objC class.
I have created a YourProjectName-Swift.h file.
- set "Defines Module" to YES in build setting
- check Product Module Name the same with my swift file name.
- set Install Objective-C Compatibility Header to YES
- set Objective-C Generated Interface Header : YourProjectName-Swift.h
- then Import Swift interface header in *.m file.
#import "YourProjectName-Swift.h"
My swift class is:
@objc public class MySwiftClass: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
addBehavior()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
addBehavior()
}
func addBehavior() {
print("Add all the behavior here")
}
}
How can I access this class from an Objective-C file?
I tried to initiate my swift class object with the below, but it's not working.
MySwiftClass *swift = [[MySwiftClass alloc] init];