gpt4 book ai didi

ios - swift EXC_BAD_INSTRUCTION

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:32 36 4
gpt4 key购买 nike

我尝试编写游戏代码(我使用本教程 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.
}
}

首先我得到“Thread 1: signal 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)

调试后 > 继续,我得到线程 1:EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)

就是这样。

有人可以帮我吗?

最佳答案

读取崩溃日志输出;它说:

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.'

所以问题是您已经配置了一些东西(可能是 XIB 或 Storyboard 中的一个对象)来访问 ticTac01,它似乎没有在您的类中定义。我的猜测是,这可能是您拥有的变量之一的早期名称?

关于ios - swift EXC_BAD_INSTRUCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24860891/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com