Reputation: 41
I'm subclassing NSURLRequest. Creating custom init methods for the class created. While coding, i ended up with the following error.. "'required' initializer 'init(coder:)' must be provided by subclass of 'NSURLRequest'"...
My code is
import Foundation
class URLRequest: NSURLRequest {
init (UrlRequestWithURL: NSString, setHTTPBody: NSData, shouldHandleCookies: Bool, isHTTPMethodPost: Bool, withTimeoutInterval: NSTimeInterval)
{
}
// Here it shows the error
}
Help me regarding this..
Apart from the above question....
Do i really need to subclass NSUrlRequest.. (Purpose of creating urlrequest variable, is that creating several requests that have to assigned for urlsession variable.) Else is there any other way that the purpose gets satisfied?
How to create a singleton class in swift. All these days i worked with objc. I find hard in formulating it.
Upvotes: 0
Views: 1424
Reputation: 10407
I would avoid subclassing NSURLRequest. I've encountered very strange behavior when I do so (and progressively worse misbehavior the farther back you support iOS-version-wise).
You're better off adding category methods and using NSURLProtocol's propertyForKey:inRequest:
and setProperty:forKey:inRequest:
methods.
Upvotes: 0