ios - Swift - Why init(coder) is required in AFHTTPSessionManager? -


i'm not experienced in ios development. while making subclass of afhttpsessionmanager xcode suggested me include required init(coder):

import uikit  let _sharedapimanager = apimanager(baseurl: nsurl(string: api_url)!)  class apimanager: afhttpsessionmanager {      /**      * singleton service       * (https://github.com/hpique/swiftsingleton)      */     class var sharedinstance : apimanager {         return _sharedapimanager     }      init(baseurl url: nsurl!) {         super.init(baseurl: url, sessionconfiguration: nil)          self.responseserializer = afjsonresponseserializer() afjsonresponseserializer         self.requestserializer = afjsonrequestserializer() afjsonrequestserializer          self.requestserializer.setvalue(api_key, forhttpheaderfield: "x-api-key")         self.requestserializer.setvalue("3", forhttpheaderfield: "x-api-version")     }      // inserted xcode     required init(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     } } 

my main question why it's required? far know nscoder deals storyboards related code (e.g. called when nib loads).

related question class not implement superclass's required members contains info mean swift classes extend objective-c ones need it?

initwithcoder: , encodewithcoder: used time encode , decode objects, writing / reading disk. you're right storyboards use this, it's common way save data in between app launches.

afhttpsessionmanager implements method can encode session manager if want. because it's implemented there, must override in subclass, , set or decode non-optional properties before call super.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -