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 

enter image description here

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


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo