objective c - Data passing between two View Controller Swift IOS -


i have been making simple gpa calculation app. , takes user input lot of text fields , calculate , show result.i want show result in 2ndviewcontroller

@ibaction func calculategpa(sender: anyobject){ //all calculation happen here //example         let gpa:float = totalgici/totalgi  } 

and want pass gpa 2ndviewcontroller label. did coding this

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         var resultviewcontroller : viewcontrollerresult = segue.destinationviewcontroller as! viewcontrollerresult          resultviewcontroller.gparesultlabel = "\(gpa)"     } 

then got error saying use of unresolved identifier gpa

what can here?

i tried removing @ibaction func calculategpa(sender: anyobject){ , replacing override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { because sender anyobject. got error

unrecognized selector sent instance

define variable globally var because variables declared let must assigned value. cannot define variable let , no value you're trying on first line.

if modifying value @ runtime, not constant is. thus, need variable, if value changes once.

class viewcontroller:uiviewcontroller{  // define  variable gpa here return type...    var gpa:float?     override func viewdidload() {     super.viewdidload()     //   relevant code }  @ibaction func calculategpa(sender: anyobject){     gpa = totalgici/totalgi }  // data passing code 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -