i new swift , trying convert line of code objective-c swift. here's objective-c code:
first off, objective c code terms , locations this:
nsstring *term = [[nsuserdefaults standarduserdefaults] valueforkey:@"term"] ?: defaultterm; nsstring *location = [[nsuserdefaults standarduserdefaults] valueforkey:@"location"] ?: defaultlocation; i translated swift (which i'm not sure how account ?: defaultterm)
var term: anyobject? = nsuserdefaults.standarduserdefaults().valueforkey("term"); var location: anyobject? = nsuserdefaults.standarduserdefaults().valueforkey("location"); var apisample:ypapisample = ypapisample(); and query in objective-c: [apisample querytopbusinessinfoforterm:term location:location completionhandler:^(nsdictionary *topbusinessjson, nserror *error) {

when type swift code, comes out this
apisample.querytopbusinessinfoforterm(term, location: location) { (topbusinessjson, error) -> void in code } i tried removing -> , void doesn't seem it.
does work?
// cast results come userdefaults var term: string? = nsuserdefaults.standarduserdefaults().valueforkey("term") as? string var location: string? = nsuserdefaults.standarduserdefaults().valueforkey("location") as? string apisample.querytopbusinessinfoforterm(term, location: location, completionhandler: { (topbusinessjson: [nsobject: anyobject]!, error: nserror!) -> void in //code })
Comments
Post a Comment