ios - Swift Function Error: 'Float' is not convertible to 'Void' -


i have following function, generates quick nsurlconnection request , returns contents of page. function gives me error on return line 'float' not convertible 'void'

func getdji(year: int, month: int, day: int) -> float {     let baseurl = "http://geo.crox.net/djia"      var request = nsmutableurlrequest(url: nsurl(string: string(format:"%@/%02d/%02d/%02d",baseurl, year, month, day))!)     httpget(request){         (data, error) -> void in         if error != nil {             println(error)         } else {             return (data nsstring).floatvalue         }     } } 

what going wrong?

there 2 problems here.

first, you've got closure supposed return void , you're trying return float it, , second, you've got function supposed return float, never return it.

what might make sense outer function return void, , accept closure expects float , returns void:

func getdji(year: int, month: int, day: int, completion:(float)->void) -> void {     let baseurl = "http://geo.crox.net/djia"      var request = nsmutableurlrequest(url: nsurl(string: string(format:"%@/%02d/%02d/%02d",baseurl, year, month, day))!)     httpget(request){         (data, error) -> void in         if error != nil {             println(error)         } else {             completion((data nsstring).floatvalue)         }     } } 

and record... (data nsstring).floatvalue looks pretty suspicious me...


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -