Is it possible to call Swift convenience initializer in Objective-C
Yes we can use it Note: @objc and public are important
@objc public init(url: URL) {
//your code
}
Check out Using Swift with Cocoa and Objective-C (Swift 2.2) - Mix and Match. What it seems to come down to is
- Making your convenience initializer
public
, and - Importing an XCode-generated header file
[YourProductModuleName]-Swift.h
into your code
Please note! If you are using any of Swift features that are not available in Objective-C (like Optional values), it would not be accessible in Objective-C. So fix them.
public convenience init(title:String?, message:String?) {
self.init()
self.title = title
self.message = message
}
Above code is not accessible, so removing optional will help in this case.