ios8 - NSJSONSerialization json data from Swift dictionary containing struct as values -


i trying convert swift dictionary (that has string keys , struct values) json data using nsjsonserialization. getting error:

cannot invoke 'datawithjsonobject' argument list of type'([string : vik.version], options: nsjsonwritingoptions, error: nil) 

is there missing. appreciated.

thanks

following code.

final class vik: nsobject {      private struct version {        private var name: string        private var filestoadd = [string]()        private var filestoremove = [string]()         init(name: string, filestoadd: [string]?, filestoremove: [string]?) {           self.name = name            if let filestoadd = filestoadd {             self.filestoadd = filestoadd           }            if let filestoremove = filestoremove {             self.filestoremove = filestoremove           }        }     }     ......     ......     ......      private var changelogdict = [string : version]()      private func addtodirectory() {        .......        .......        let jsondata = nsjsonserialization.datawithjsonobject(self.changelogdict, options: nsjsonwritingoptions.prettyprinted, error: nil)        .......        .......     }  } 

i figured out. nsjsonserialization.datawithjson method takes 'anyobject' data type. swift dictionary struct not object , hence complaining. following line compiles fine

let jsondata = nsjsonserialization.datawithjsonobject(self.changelogdict nsdictionary, options: nsjsonwritingoptions.prettyprinted, error: nil) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -