ios - swift Completion handlers cannot convert value of type to specified type -
i'm trying implement completion handlers i'm getting error:
cannot convert value of type specified type.
here code:
override func viewdidload() { super.viewdidload() let sss : string = dosomethingelse { (data) in } print(sss) } func dosomethingelse(completion:(data:string) -> void) { let s = "blablabla" print(s) completion(data:s) }
on line i'm getting error:
let sss : string = dosomethingelse { (data) in
any of knows why i'm getting error?
i'll appreciate help.
you have declared sss
string
have attempted assign closure it; compiler gives error.
i think trying assign closure sss
, pass closure dosomethingelse
:
func viewdidload() { super.viewdidload() let sss : ((data:string) -> void) = { data in print ("data \(data)") } dosomethingelse(sss) } func dosomethingelse(completion:(data:string) -> void) { let s = "blablabla" print(s) completion(data:s) }
which give following output:
blablabla
data blablabla