How do you access a variable outside a function in swift -
i trying access inputac , inputb outside function getvariables , can't seem working.
here code working work.
func getvariables () { var inputac = textfieldac.text.toint() var inputb = textfieldb.text.toint() } var ac = inputac var b = inputb
anyone have ideas?
thanks
you need homecoming values function. here 1 way returning them in tuple:
func getvariables () -> (int?, int?) { var inputac = textfieldac.text.toint() var inputb = textfieldb.text.toint() homecoming (inputac, inputb) } var (ac, b) = getvariables() // since values optionals, can utilize optional binding // safely disclose value. if allow acval = ac { println("ac value \(acval)") } else { println("alas, ac nil") }
function variables swift
No comments:
Post a Comment