Q: sharing variables between classes in Swift I am just getting into Swift and struggling how to simply set a text property of a label in one class based on a variable in another. In one swift file I have:
Class GameController:

var instructsText = String()

func gameControl()
instructsText = array[2] as string //this gets the instructions text from a Plist file.

In another swift file I have
Class HelpViews: UIView {

override init(frame: CGRect) {

// add the instructions label
var instructsLabel = UILabel(frame: CGRectMake(ScreenWidth/2-300, ScreenHeight-150, 600, 100))
instructsLabel.text = instructsText - ERROR 'instructs is not a subtype of 'NSString'
self.addSubview(instructsLabel)

any help very much appreciated!

A: It is unclear why you would be getting the error you say you are. At no point, (at least in the code above) do you make an object of the GameController Class and thus the compiler should be telling you that it does not recognize the variable instructsText. However, I would suggest using a computed class property. An example of one would be:
class MyClass {
class var pi: Double { return 3.1415926 }
// ...
}
println(MyClass.pi)

Which would print out 3.1415926. In you code, one way that might work is as follows:
Class GameController:

class var instructsText = String {return array[2] as String}

And in the HelpView Class:
Class HelpViews: UIView {

override init(frame: CGRect) {

// add the instructions label
var instructsLabel = UILabel(frame: CGRectMake(ScreenWidth/2-300, ScreenHeight-150, 600, 100))
instructsLabel.text = GameController.instructsText
self.addSubview(instructsLabel)

The Apple Swift documentation is here.

A: Try first to println(instructsText) variable, to see what you try to set.
Here is a few cases:


*

*Not declared variable

*It could be nil

*It's not String

