线程 1:EXC_BAD_INSTRUCTION(代码=EXC_1386_INVOP,子代码=0x0)
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP,subcode=0x0)
非常接近真正让这个应用程序移动起来。还有一个问题。现在,我的应用程序将 运行,当下一个视图控制器试图显示时它会给我一个错误。我正在展示一个带有引用和作者的 ViewController。我得到这个错误
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
}
}
提前致谢!
编辑 2021 年 12 月:替换图像以省略名称
由于用力展开它正在崩溃。
最佳做法是使用 IF LET 检查数据是否存在,因为 IF LET 会这样做(展开)。
This way Try once :
if let mStringvalue = businessQuote.dict[chosenQuote]{
print(mStringvalue)
}
非常接近真正让这个应用程序移动起来。还有一个问题。现在,我的应用程序将 运行,当下一个视图控制器试图显示时它会给我一个错误。我正在展示一个带有引用和作者的 ViewController。我得到这个错误
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
}
}
提前致谢!
编辑 2021 年 12 月:替换图像以省略名称
由于用力展开它正在崩溃。
最佳做法是使用 IF LET 检查数据是否存在,因为 IF LET 会这样做(展开)。
This way Try once :
if let mStringvalue = businessQuote.dict[chosenQuote]{
print(mStringvalue)
}