0

In My project i have two file ViewController.swift and ButtonViewController.swift . In ViewController i have this code

var nomeLabel:String!
func goToView(sender: UIButton!) {
// self.performSegueWithIdentifier("goToView", sender: self) // I used This for Go to Second View in Another moment
var label: UILabel = UILabel()
label.frame = CGRectMake(self.view.frame.size.width/2, 10, 150, 21);
label.backgroundColor = UIColor.blackColor()
label.textColor = UIColor.whiteColor()
label.textAlignment = NSTextAlignment.Center
label.text = "\(self.nomeLabel)"
self.myView.addSubview(label)
})
}

and now I want to take the value of the variable self.nomeLabel in the second file ButtonViewController.swift. how can I view this variable in ButtonViewController.swift ?

Massimo Negro
  • 65
  • 1
  • 8
  • 1
    Not clear enough. What is 'button.swift'? what is 'nomeLabel'? (I 'guess' a UILabel?). And this line: _"import in the one Label on second file"_. What do you mean 'import in'? What is 'the one', what is 'the second'. Hard to figure what is it you're asking. In you code, there's a `func` that adds a label to some view. There's really not much there. – bauerMusic Nov 18 '14 at 04:17
  • I edited my question, no one understood very well before. – Massimo Negro Nov 18 '14 at 08:35
  • Looks very similar to this other question (answered): http://stackoverflow.com/questions/24333142/access-variable-in-different-class-swift – sabi Nov 18 '14 at 09:47
  • Yes but class Main { var name:String init(name:String) { self.name = name } } var mainInstance = Main(name:"My Global Class") I can enter in the ViewController instead of creating the global.swift ? – Massimo Negro Nov 18 '14 at 09:51
  • I had seen this question but I'm sorry ,I'm not able to develop this with my example – Massimo Negro Nov 18 '14 at 10:03
  • What is Button.swift? Is it a subclassed UIButton? – Ron Fessler Nov 18 '14 at 19:41
  • one file in my project I'm sorry I changed the name – Massimo Negro Nov 18 '14 at 19:43
  • Just declare the variable _outside_ your class, then other classes can access it. – tomjpsun Dec 02 '14 at 01:11

0 Answers0