嗨,我正在尝试以相反的顺序打印数组元素,但我收到了类似的错误
数组索引超出范围。
你们能帮帮我吗?我在下面发布我的代码
import UIKit
class DecimalToBinaryViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var result: UILabel!
@IBAction func binaryNumber(sender: AnyObject)
{
var myArray = [Int]()
var number = textField.text.toInt()
var num = Int(number!) // for converting optional Int? to Int
var remainder:Int
var condition = false
while condition == false
{
remainder = num % 2
myArray += [remainder]
num /= 2
if num == 0
{
condition = true
}
}
var size = myArray.count
for var i = size; i >= 0; i--
{
println( myArray[i])
}
}