title: AFHTTPSessionManager subclass swift
body: <p>What is the correct way to create singletone subclass of AFHTTPSessionManager with custom session configuration?</p>
  
  <pre><code>class DefaultSessionConfiguration: NSURLSessionConfiguration {
  
      override init () {
  
          super.init()
  
          self.HTTPShouldSetCookies = true
          HTTPCookieStorage?.cookieAcceptPolicy = NSHTTPCookieAcceptPolicy.Always
          HTTPAdditionalHeaders = [ "Content-Type": "application/json"];
      }
  
  }
  
  let baseUrl = "https://google.com"
  
  class HTTPManager: AFHTTPSessionManager {
  
  
      static let _sharedAPIManager = HTTPManager(baseURL: NSURL(string: baseUrl)!, sessionConfiguration:DefaultSessionConfiguration())
  
      class var sharedInstance : HTTPManager {
          return _sharedAPIManager
      }
  
      override init(baseURL url: NSURL!, sessionConfiguration session:NSURLSessionConfiguration? ) {
  
          super.init(baseURL: url, sessionConfiguration: session)
          self.responseSerializer = AFJSONResponseSerializer() as AFJSONResponseSerializer
          self.requestSerializer = AFJSONRequestSerializer() as AFJSONRequestSerializer
  
      }
  
  }
  </code></pre>
  
  <p>While trying to use this code as  <code>self.sessionManager = HTTPManager.sharedInstance</code> it is always crashed with message</p>
  
  <blockquote>
    <p>[MyApp.DefaultSessionConfiguration setHTTPShouldSetCookies:]:
    unrecognized selector sent to instance 0x7f99f8f31b70</p>
  </blockquote>
  
  <p>but MyApp.DefaultSessionConfiguration is subclass of NSURLSessionConfiguration and defenetly has this method.</p>
  
  <p>So, how do we solve this problem?</p>