Subclass doesn't inherit convenience initialiser

Hello,

I'm subclassing NSMutableURLRequest to patch lack of httpBody property. My subclass doesn't implement any initialisers so it inherits all the designated initialisers. From what I understand, since all designated initialisers are implemented(inherited) then I should also inherit convenience initialisers.

My code:
class safe_NSMutableURLRequest: NSMutableURLRequest {
#if os(Linux)
var httpBody: NSData?
#endif
}

let someURL = NSURL(string: "https://google.com")!
let request = safe_NSMutableURLRequest(url: someURL)

the last line produces an error:
error: incorrect argument label in call (have 'url:', expected 'coder:')

Could you please explain me why I'm not inheriting convenience initialiser?

Regards,
Michal Kalinowski

Which swift version are you using? Your code works correctly for me on Swift 2.2 in the Playgrounds, apart from the wrong letter casing of the argument label (should be `URL`, not `url`).

On the separate note, your usecase seems like a great place for writing an extension of NSMutableURLRequest instead of inheriting from it.

Best,
Krzysztof

ยทยทยท

On 30 May 2016 at 21:00:12, Michal Kalinowski via swift-users (swift-users@swift.org) wrote:

Hello,

I'm subclassing NSMutableURLRequest to patch lack of httpBody property. My subclass doesn't implement any initialisers so it inherits all the designated initialisers. From what I understand, since all designated initialisers are implemented(inherited) then I should also inherit convenience initialisers.

My code:
class safe_NSMutableURLRequest: NSMutableURLRequest {

#if os(Linux)

var httpBody: NSData?

#endif

}

let someURL = NSURL(string: "https://google.com")!

let request =

safe_NSMutableURLRequest(url: someURL)

the last line produces an error:

error: incorrect argument label in call (have 'url:', expected 'coder:')

Could you please explain me why I'm not inheriting convenience initialiser?

Regards,

Michal Kalinowski

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users