Printing json in swift after download/parse -


i'm trying json website , parse before printing it. i've got class called "jsonimport", should handle json import server , print it. second class should make call start import , print content of json.

the following code have far (i took question downloading , parsing json in swift)

so "jsonimport.swift":

var data = nsmutabledata();  func startconnection(){     let urlpath: string = "http://echo.jsontest.com/key/value";     let url: nsurl = nsurl(string: urlpath)!;     let request: nsurlrequest = nsurlrequest(url: url);     let connection: nsurlconnection = nsurlconnection(request: request, delegate: self, startimmediately: false)!;     connection.start(); }  func connection(connection: nsurlconnection!, didreceivedata data: nsdata!){     self.data.appenddata(data); }  func connectiondidfinishloading(connection: nsurlconnection!) {     // throwing error on line below (can't figure out error message is)     do{      let jsonresult: nsdictionary = try nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers) as! nsdictionary;         print(jsonresult);}     catch {         print("something went wrong?");     } } 

inside class, print json by:

jsonimport.startconnection(); 

now error, because swift wants me add parameter call, making like:

jsonimport.startconnection(<#t##jsonimport#>); 

does have idea, should put in there parameter? confused, didn't declare one.

thank in advance!

kind regards, manuel

startconnection() instance method, need instantiate jsonimport call it.

only type methods can used way. it's asking instance of jsonimport.

here how should it

let importer = jsonimport() importer.startconnection() 

or calling type method

let importer = jsonimport() jsonimport.startconnection(importer) 

you can read more instance/type methods @ guide


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 -