xcode 斯威夫特 EXC_BAD_INSTRUCTION
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24860891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift EXC_BAD_INSTRUCTION
提问by user2996927
I try to code a game (i use this tutorial https://www.youtube.com/watch?v=LkYpoRj-7hAim new in Swift). Thats my Code so far:
我尝试编写游戏(我使用本教程https://www.youtube.com/watch?v=LkYpoRj-7hA我是 Swift 新手)。到目前为止,这是我的代码:
import UIKit
class ViewController: UIViewController {
//Image View
@IBOutlet var ticTac_A01: UIImageView = nil
@IBOutlet var ticTac_A02: UIImageView = nil
@IBOutlet var ticTac_A03: UIImageView = nil
@IBOutlet var ticTac_B01: UIImageView = nil
@IBOutlet var ticTac_B02: UIImageView = nil
@IBOutlet var ticTac_B03: UIImageView = nil
@IBOutlet var ticTac_C01: UIImageView = nil
@IBOutlet var ticTac_C02: UIImageView = nil
@IBOutlet var ticTac_C03: UIImageView = nil
//Buttons
@IBOutlet var ticTacBtn_A01: UIButton = nil
@IBOutlet var ticTacBtn_A02: UIButton = nil
@IBOutlet var ticTacBtn_A03: UIButton = nil
@IBOutlet var ticTacBtn_B01: UIButton = nil
@IBOutlet var ticTacBtn_B02: UIButton = nil
@IBOutlet var ticTacBtn_B03: UIButton = nil
@IBOutlet var ticTacBtn_C01: UIButton = nil
@IBOutlet var ticTacBtn_C02: UIButton = nil
@IBOutlet var ticTacBtn_C03: UIButton = nil
@IBOutlet var resetBtn: UIButton = nil
@IBOutlet var userMessage: UILabel = nil
var plays = Dictionary<Int, Int>()
var done = false;
var aiDeciding = false;
@IBAction func UIButtonClicked(sender : UIButton){
userMessage.hidden = true;
if !plays[sender.tag] && !aiDeciding && !done {
setImageForSpot(sender.tag, player:1)
}
checkForWin()
aiTurn()
}
func setImageForSpot(spot:Int, player:Int){
var playerMark = player == 1 ? "x" : "o"
plays[spot] = player
switch spot {
case 1:
ticTac_A01.image = UIImage(named: playerMark)
case 2:
ticTac_A02.image = UIImage(named: playerMark)
case 3:
ticTac_A03.image = UIImage(named: playerMark)
case 4:
ticTac_B01.image = UIImage(named: playerMark)
case 5:
ticTac_B02.image = UIImage(named: playerMark)
case 6:
ticTac_B03.image = UIImage(named: playerMark)
case 7:
ticTac_C01.image = UIImage(named: playerMark)
case 8:
ticTac_C02.image = UIImage(named: playerMark)
case 9:
ticTac_C03.image = UIImage(named: playerMark)
default:ticTac_B02.image = UIImage(named: playerMark)
}
}
func checkForWin(){}
func aiTurn(){}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
First i i get the ?Thread 1: signal SIGABRT“ with this Output:
首先 ii 通过此输出获得“线程 1:信号 SIGABRT”:
2014-07-21 10:26:21.709 Swift-Tac-Toe[3264:107207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_TtC13Swift_Tac_Toe14ViewController 0x7f8160ca0f00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ticTac01.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001010a3055 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102b5da1c objc_exception_throw + 45
2 CoreFoundation 0x00000001010a2c99 -[NSException raise] + 9
3 Foundation 0x00000001014b67a3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000100fed950 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x0000000101bdb58d -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000101a42898 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x0000000101a42f49 -[UIViewController loadView] + 109
8 UIKit 0x0000000101a431ba -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x0000000101a4364f -[UIViewController view] + 27
10 UIKit 0x0000000101964d79 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x0000000101965112 -[UIWindow _setHidden:forced:] + 276
12 UIKit 0x0000000101971e70 -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010191cc31 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2673
14 UIKit 0x000000010191f5cc -[UIApplication _runWithMainScene:transitionContext:completion:] + 1222
15 UIKit 0x000000010191e5ac -[UIApplication workspaceDidEndTransaction:] + 19
16 FrontBoardServices 0x0000000104357263 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x0000000100fd909c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x0000000100fce805 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x0000000100fce5c5 __CFRunLoopRun + 2389
20 CoreFoundation 0x0000000100fcda06 CFRunLoopRunSpecific + 470
21 UIKit 0x000000010191dfc2 -[UIApplication _run] + 413
22 UIKit 0x0000000101920cf8 UIApplicationMain + 1282
23 Swift-Tac-Toe 0x0000000100c224fd top_level_code + 77
24 Swift-Tac-Toe 0x0000000100c2253a main + 42
25 libdyld.dylib 0x00000001030ce145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
After Debug > Continue i get Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
调试 > 继续后,我得到Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)。
and thats it.
就是这样。
Anyone can help me here?
任何人都可以在这里帮助我吗?
回答by alastair
Read the crash log output; it says:
读取崩溃日志输出;它说:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_TtC13Swift_Tac_Toe14ViewController 0x7f8160ca0f00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ticTac01.'
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<_TtC13Swift_Tac_Toe14ViewController 0x7f8160ca0f00> setValue:forUndefinedKey:]:此类不符合密钥 ticTac01 的键值编码。”
So the problem is that you have configured something (possibly an object in a XIB or Storyboard) to access ticTac01
, which doesn't appear to be defined in your class. My guess is that that might have been an earlier name for one of the variables you dohave?
所以问题是你已经配置了一些东西(可能是 XIB 或 Storyboard 中的一个对象)来访问ticTac01
,它似乎没有在你的类中定义。我的猜测是,这可能已经为您的一个变量是一个早期的名字也有吗?