I am playing with Swift and Xcode. This works in playground:
[["1","2"], ["3","4"]][0]
But this does not work in Xcode project:
enum UnitSystem: Int {
case Standard = 0
case Metric = 1
}
class ViewController: UIViewController, UITextFieldDelegate, UIPickerViewDelegate {
@IBOutlet weak var unitSystemControl: UISegmentedControl! //"Standard" and "Metric"
var units: [[String]]! = nil
var currentUnitSystem: UnitSystem! = nil
override func viewDidLoad() {
super.viewDidLoad()
...
currentUnitSystem = UnitSystem(rawValue: unitSystemControl.selectedSegmentIndex)
units = [["ft.", "in."], ["m.", "cm."]][currentUnitSystem.rawValue]
}
...
...
}
I am getting this error: Type '[String]' does not conform to protocol 'StringLiteralConvertible'
Questions:
- How to deal with this error?
- Is there a cleaner/better way to switch out the units on the fly?
- It seems like I don't quite grasp the whole idea of ! and ? types in Swift, is there an easy-to-understand tutorial somewhere?
Thank you!
var units: [[String]]! = nil, making itvar units: [String]? = nilmakes it work. The last two questions still stand, though. - Dormidont