Overriding init method in Swift for Objective-C class with naming conflict

I am trying to subclass the IBMDataObject from the Mobile Data SDK on Bluemix. The IBMData framework in written in Objective-C, so the init method I am trying to override, looks like this:

- (instancetype)initWithClass:(NSString *)classname;

Using this in Swift, it gets converted to:

init!(withClass classname: String!) {
    super.init(withClass: classname)

This must conflict with a naming convention check in Swift, because I then get the error:

Having the word class in the init method name seems to cause an issue because the auto-fix deletes withClass and puts in the keyword class.

I am not sure if there is a workaround for this, maybe a warning suppression? Or does the IBMDataObject init method need to change it's name?


I faced the same error, fixed it by changing the override method with:

required override init() {
    super.init(withClass: "Item")

Since the init method is required to receive a string argument. <<(NSString *)classname;>>

Also changed the init method to:

init(className: String){
    super.init(withClass: className)

Hope it helps.

Need Your Help

Dynamically calculate application load time

iphone objective-c xcode

How can I run a clock that allows me to measure the time to load until appDidFinishLaunching ?