I have subclasses NSMutableURLRequest as follows:
class CustomNSMutableURLRequest: NSMutableURLRequest {
convenience init(url : URL) {
self.init(url: url)
self.httpShouldHandleCookies = false
self.httpMethod = "GET"
print("Custom Request!")
}
}
This causes an infinite loop at the self.init(url: url) line. Using super instead of self doesn't work either. How can I fix this?
Unfortunately, you cannot override the exact convenience initializer within a subclass.
You may need to write something like this:
But I'm not sure if subclassing is really needed, I would add some factory method to
URLRequestlike this: