In latest XCode 6 beta (5) I noticed that almost every class in my app complains with error:
Class does not implement its superclass's required members
For example:
import UIKit
let _sharedAPIManager = APIManager(baseURL: NSURL.URLWithString(API_URL))
class APIManager: AFHTTPSessionManager {
class var sharedInstance : APIManager {
return _sharedAPIManager
}
// this fixes compiler error but why it should be here?
required init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}
override init() {
super.init()
}
override init(baseURL url: NSURL!) {
super.init(baseURL: url)
self.responseSerializer = AFJSONResponseSerializer()
self.requestSerializer = AFJSONRequestSerializer()
self.requestSerializer.setValue(API_KEY, forHTTPHeaderField: "X-Api-Key")
self.requestSerializer.setValue("3", forHTTPHeaderField: "X-Api-Version")
}
override init(baseURL url: NSURL!, sessionConfiguration configuration: NSURLSessionConfiguration!) {
super.init(baseURL: url, sessionConfiguration: configuration)
}
The question is why it's relevant even in subclassing of AFNetworking's AFHTTPSessionManager? Did I missed something?
Because AFHTTPSessionManager
conforms to NSCoding
and initWithCoder:
is required. From manual:
initWithCoder: Returns an object initialized from data in a given unarchiver. (required)
Because your class overrides some of the superclass's designated initializers, it does not automatically inherit initializers from the superclass. If you had not overridden any initializers, then all the initializers from the superclass would be automatically inherited, and thus the required initializer from NSCoding would be satisfied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With