afnetworking - Converting mutableCopy to Swift -



afnetworking - Converting mutableCopy to Swift -

i've found guide receive http body, witch contains json formatted error message afnetworking 2. guide in objective-c , i'm trying best convert swift.

here's code i'm trying convert swift:

- (id)responseobjectforresponse:(nsurlresponse *)response data:(nsdata *)data error:(nserror *__autoreleasing *)error { if (![self validateresponse:(nshttpurlresponse *)response data:data error:error]) { if (*error != nil) { nsmutabledictionary *userinfo = [(*error).userinfo mutablecopy]; nserror *jsonerror; // parse json id json = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments error:&jsonerror]; // store value in userinfo if json has no error if (jsonerror == nil) userinfo[jsonresponseserializerwithdatakey] = json; nserror *newerror = [nserror errorwithdomain:(*error).domain code:(*error).code userinfo:userinfo]; (*error) = newerror; } homecoming (nil); } homecoming ([super responseobjectforresponse:response data:data error:error]); }

more specific it's part there's problem:

nsmutabledictionary *userinfo = [(*error).userinfo mutablecopy];

this current code:

class jsonresponseserializerwithdata: afjsonresponseserializer { allow jsonresponseserializerwithdatakey: nsstring = "jsonresponseserializerwithdatakey" override func responseobjectforresponse(response: nsurlresponse!, data: nsdata!, error: nserrorpointer) -> anyobject? { if(!self.validateresponse(response nshttpurlresponse, data: data, error: error)) { if(error != nil) { // question..... var jsonerror: nserror // parse json // missing returns anyobejct... } homecoming nil } } }

how convert line swift? i'm quite new swift / objective-c language, there might simple solution it, i've not been able find yet.

i found same guide describes how parse error message in afnetworking 2 , here implementation in swift:

override func responseobjectforresponse(response: nsurlresponse!, data: nsdata!, error: nserrorpointer) -> anyobject! { if !self.validateresponse(response as! nshttpurlresponse, data: data, error: error) { if error != nil { var userinfo = error.memory!.userinfo! var jsonerror:nserror? allow json: anyobject? = nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.allowfragments, error: &jsonerror) userinfo[jsonresponseserializerwithdatakey] = json; error.memory = nserror(domain: error.memory!.domain, code: error.memory!.code, userinfo: userinfo) } homecoming nil } homecoming super.responseobjectforresponse(response, data: data, error: error) }

hope help someone.

swift afnetworking

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -