swift - [NSKeyedUnarchiver init]: cannot use -init for initialization' error when trying to save a custom class -


i error:

[nskeyedunarchiver init]: cannot use -init initialization when trying load custom class.

heres init class:

   required init?(coder adecoder: nscoder) {         print("intializing")         if let quotename = adecoder.decodeobjectforkey("quotename") as? string {             self._quotename = quotename         }         if let quote = adecoder.decodeobjectforkey("quote") as? string {             self._quote = quote         }         if let soundfilename = adecoder.decodeobjectforkey("soundfilename") as? string {             self._soundfilename  = soundfilename         }         if let soundfiletype = adecoder.decodeobjectforkey("soundfiletype") as? string {             self._soundfiletype = soundfiletype         }         if let audiofilepath = adecoder.decodeobjectforkey("audiofilepath") as? string {             self._soundfiletype = audiofilepath         }         if let state = adecoder.decodeobjectforkey("state") as? bool {             self._state  = state         }         if let number = adecoder.decodeobjectforkey("number") as? int {             self._number = number         }      } 

heres encoder function

  func encodewithcoder(acoder: nscoder) {             acoder.encodeobject(self._quotename, forkey: "quotename")             acoder.encodeobject(self._quote, forkey: "quote")             acoder.encodeobject(self._soundfiletype, forkey: "soundfilename")             acoder.encodeobject(self._soundfiletype, forkey: "soundfiletype")             acoder.encodeobject(self._audiofilepath, forkey: "audiofilepath")             acoder.encodeobject(self._state, forkey: "state")             acoder.encodeobject(self._number, forkey: "number")     } 

any call load:

    class func loadquotelist(){     print("loading quotes")     quotelist.removeall()     var quotelistlength = defaults.integerforkey("quotelistlength")      //unarchives quote object     var unarc = nskeyedunarchiver()     if let data = defaults.objectforkey("quote") as? nsdata {         unarc = nskeyedunarchiver(forreadingwithdata: data)     }      print("loading individual quotes")     for(var index = 0; index < quotelistlength; index++){         var newquote = unarc.decodeobjectforkey("quote\(index)") as! quote         quotelist[index] = newquote         print(newquote._quotename)      } } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -