如此接近實際讓這個應用程序移動。還有一個問題。現在,我的應用程序將運行,當下一個視圖控制器試圖顯示時它會給我一個錯誤。我用一個引用和一個作者來展示一個ViewController。我得到這個錯誤線程1:EXC_BAD_INSTRUCTION(code = EXC_1386_INVOP,subcode = 0x0)
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP,subcode=0x0)
輸出如下:
fatal error: unexpectedly found nil while unwrapping an Optional
這是錯誤的代碼:
import Foundation
import UIKit
import Social
class businessQuote: UIViewController {
//============================//
//********** Outlets *********//
//============================//
let utility = Utility()
@IBOutlet weak var quoteDisplay: UILabel!
@IBOutlet weak var authorDisplay: UILabel!
//GET BACK TO THIS
//============================//
//********** General *********//
//============================//
let date = NSDate()
var Author: String = ""
var Quote: String = ""
override func viewDidLoad() {
super.viewDidLoad()
// Generates Random Number
func randomNumber(arrayLength: Int) -> Int {
let unsignedArrayCount = UInt32(arrayLength)
let unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
let randomNumber = Int(unsignedRandomNumber)
return randomNumber
}
// Importing Quotes plist File
let businessQuote = ImportList(FileName: "BusinessList")
// Selects Quote
let chosenQuote: String = businessQuote.array[randomNumber(businessQuote
.count())] as! String
let chosenAuthor = ((businessQuote.dict[chosenQuote]))! as String //This Is Where the error is
// Assigns Quote & Author to IBOutlet
Author = chosenAuthor
Quote = chosenQuote
quoteDisplay.text = Quote
authorDisplay.text = Author.uppercaseString
}
}
預先感謝您!
您的詞典元素爲nil –