Please note, this blog entry is from a previous course. You might want to check out the current one.
For the configuration – the settings of the game – create a new class which will handle the communication with the user defaults. Most of the variables stored in the settings are optional, as a way when to use default values.
The columns and the rows setting hold the dimensions of the level “one” of the brick wall:
struct Const { static let ColumnsKey = "Settings.Columns" static let RowsKey = "Settings.Rows" } let defaults = NSUserDefaults.standardUserDefaults() var columns: Int? { get { return defaults.objectForKey(Const.ColumnsKey) as? Int} set { defaults.setObject(newValue, forKey: Const.ColumnsKey) } } var rows: Int? { get { return defaults.objectForKey(Const.RowsKey) as? Int} set { defaults.setObject(newValue, forKey: Const.RowsKey) } }
Continue reading “cs193p – Project #5 Assignment #5 Step #5 – The Configuration”