ios - Passing SubClass Variable in sendSynchronousRequest Method in Swift -
i have next code:
var error : nserror? var response : nshttpurlresponse? var urldata : nsdata = nsurlconnection.sendsynchronousrequest ( request, returningresponse: &response, error: &error ) nsdata
returningresponse
takes instance of nsurlresponse
mentioned in reference docs.
im using nshttpurlresponse
subclass of nsurlresponse
. works fine in objective-c not know how write in swift because compiler throws error on line.
the error is: cannot convert expression's type 'nsdata' type 'inout nshttpurlresponse'
what mean? , how right?
the problem passing different type method expecting. should still pass in nsurlresponse
. can cast type afterwards:
var urldata = nsurlconnection.sendsynchronousrequest ( request, returningresponse: &response, error: &error ) if allow httpresponse = response as? nshttpurlresponse { // work http response }
also note, type of urldata can inferred homecoming type of method. there no need specify type nor convert result nsdata removed both of those.
ios objective-c cocoa swift
No comments:
Post a Comment