在Playground中编译的编译错误

我有下面的代码,如果检查在操场符合确定(除了由行动触发的function)…但在我的应用程序,我收到7编译错误。

我的代码:

import UIKit class LocationViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { @IBOutlet weak var DisplayStartMileage: UITextField! @IBOutlet weak var labelFuelAmount: UILabel! @IBOutlet weak var spinFuelAmount: UIPickerView! var mileageToPass: String! var fuelAmount: Double = 0.00 var poundValues = [String]() var penceValues = [String]() for var indexP:Int = 0; indexP < 100; indexP += 1 { poundValues.append("£ \(indexP)") penceValues.append(NSString(format: ".%02d", indexP) as String) } let pickerData = [poundValues, penceValues] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. DisplayStartMileage.text = mileageToPass; spinFuelAmount.delegate = self spinFuelAmount.dataSource = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func FuelSegmentChanged(sender: UISegmentedControl) { switch sender.selectedSegmentIndex { case 0: labelFuelAmount.hidden = false spinFuelAmount.hidden = false case 1: labelFuelAmount.hidden = true spinFuelAmount.hidden = true default: break; } } func numberOfComponentsInPickerView(spinFuelAmount: UIPickerView) -> Int { return pickerData.count } func pickerView(spinFuelAmount: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return pickerData[component].count } func pickerView(spinFuelAmount: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { return pickerData[component][row] } func pickerView(spinFuelAmount: UIPickerView, didSelectRow row: Int, inComponent component: Int) { let fuelAmount = Int(pickerData[0][spinFuelAmount.selectedRowInComponent(0)].stringByReplacingOccurrencesOfString("£ ", withString: "")) + Int(pickerData[1][spinFuelAmount.selectedRowInComponent(1)].stringByReplacingOccurancesOfString(".", withString: ""))/100 } 

}

现在我知道SO不是用于debugging的,但是我不知所措,大部分代码都依赖于Playground,而我的ViewController类中的很多代码都是在Playground错误中执行的。

我将poundValuespenceValues作为成员属性,并在viewDidLoad()设置所有这些东西:

 var pickerData = [[String]]() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. DisplayStartMileage.text = mileageToPass; var poundValues = [String]() var penceValues = [String]() for var indexP:Int = 0; indexP < 100; indexP += 1 { poundValues.append("£ \(indexP)") penceValues.append(NSString(format: ".%02d", indexP) as String) } self.pickerData = [poundValues, penceValues] spinFuelAmount.delegate = self spinFuelAmount.dataSource = self } 

更新

这是一个pickerView(_:didSelectRow:inComponent)方法的build议:

 func pickerView(spinFuelAmount: UIPickerView, didSelectRow row: Int, inComponent component: Int) { var firstComponent = pickerData[0][spinFuelAmount.selectedRowInComponent(0)] firstComponent = firstComponent.stringByReplacingOccurrencesOfString( "£ ", withString: "" ) var secondComponent = pickerData[1][spinFuelAmount.selectedRowInComponent(1)] secondComponent = firstComponent.stringByReplacingOccurrencesOfString( "£ ", withString: "" ) if let firstValue = Int(firstComponent), let secondValue = Int(secondComponent) { let fuelAmount = firstValue + secondValue / 100 } }