arrays - How to wrapped JSON Handler in Function -
so i'm using function pass json value (any object) in other class it's full of issues can't working
func getswpeopleapi() -> nsmutablearray { var json2: nsmutablearray alamofire.request(.get, "http://swapi.co/api/people/1").responsejson { response in print(response.request) print(response.response) print(response.data) print(response.result) if let json = response.result.value{ json2 = json as! nsmutablearray } else{ return } } return json2 }
do have suggestion on how can achieve pass apimanagerclass , data type best use when dealing json?
you doing in wrong way! json
must have type of nsdictionary
.
func getswpeopleapi(strurl: string, completionhandler: (nsdictionary?, nserror?) -> ()) -> (){ alamofire.request(.get, strurl).responsejson { response in switch response.result { case .success(let data): let json = data as? nsdictionary completionhandler(json, nil) case .failure(let error): completionhandler(nil, error) } }
here code completion handler , error specified!
how use:
postwebservicewithurl(url!) { (responsedata, error) -> () in //code }
Comments
Post a Comment