Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Where to store strings in swift?

Hi guys,

Im a bit confused about the right place to store string variables in a game for ios developed in swift.

Right now Im storing them in a class named "GameConstants" like this:

public class GameConstants {

class var fontSize:CGFloat{
    return 32
}

class var achievementsLabelSize:CGFloat{
    return 26
}

class var fontName:String{
    return "Futura"
}

But I dont think this is the right way to do it and I feel very uncomfortable about it.

Can anyone give me some orientation?

1 Answer

Hey there - no need to use a special class to store strings, and DEFINITELY don't create a class for each string you want to store. Anywhere in your code, you can simply create a variable and store your string or integer in it:

var fontSize = 32

var achievementsLabelSize = 26

var fontName = "Futura"