4

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?

Kosmetika
  • 19,249
  • 37
  • 94
  • 154

2 Answers2

6

Because AFHTTPSessionManager conforms to NSCoding and initWithCoder: is required. From manual:

initWithCoder: Returns an object initialized from data in a given unarchiver. (required)

Neeku
  • 3,538
  • 8
  • 31
  • 42
Kirsteins
  • 25,621
  • 8
  • 72
  • 75
6

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.

newacct
  • 110,405
  • 27
  • 152
  • 217