Using a variable of a .swift file in another .swift file of same project -


i want use value variable alarmvalint in alarmviewcontroller. below small portion of

alarmviewcontroller.swift:

class alarmviewcontroller: uiviewcontroller {      @iboutlet weak var alarmtextfield: uitextfield!      @iboutlet weak var alarmlabel: uilabel!      @ibaction func alarmok(sender: anyobject) {         let alarmvalfloat:float = nsstring(string: alarmtextfield.text).floatvalue         let alarmvalint:int = nsstring(string: alarmtextfield.text).integervalue         var alarmvaldec:float = alarmvalfloat - float(alarmvalint)         var alarmvalsec = alarmvaldec*100         //println("\(alarmvalsec),\(alarmvaldec*100)")         if (alarmvalfloat <= 10) {             alarmlabel.text = "h2s alarm level = \(alarmvalint)min:\(alarmvalsec)sec"         }         else {             alarmlabel.text = "invalid time. enter <= 10"         }         self.alarmtextfield.resignfirstresponder()     } 

and want "append" value of alarmvalint array graphpoints in graphview.swift. small portion (starting few lines) of file:

graphview.swift

import uikit  @ibdesignable class graphview: uiview {    //weekly sample data   var graphpoints:[int] = [4, 2, 6, 4, 5, 10, 3]   //var graphpoints:[int] = [0]    //graphpoints.append(alarmviewcontroller.alarmok.alarmvalint) //not surprised did not work 

how can use variable value first file , append value array in second file?

ans: assuming might have same question @ point way solved is: in alarmviewcontroller.swift: graphview.graphpoints.append(8)//8 appended array graphpoints

note: graphview subview of view in alarmviewcontroller view

you've declared alarmvalint local variable inside alarmok method. declare instance variable (outside of method, @iboutlets declared). need instantiate instance of alarmviewcontroller class. assuming you've called alarm:

graphpoints += alarm.alarmvalint 

of course, if you're using alarmvalint constant (declared using let), there's no need instantiate instance of class. use so:

graphpoints += alarmviewcontroller.alarmvalint