[英]Swift: app runs well in simulator but crashes on actual iPhone?
I am a beginner and I created a kind of tic tac toe game and have been running it on the iPhone 5s simulator to weed out issues and just now I tried it out on my actual iPhone 5s and the app crashes when the AI is supposed to take its turn. 我是一个初学者,我创建了一种tic TAC Toe游戏,并一直在iPhone 5s模拟器上运行它以清除问题,而现在我在实际的iPhone 5s上进行了尝试,并且当AI被认为会导致应用崩溃轮到它了。 Xcode draws an error (EXC_BAD_ACCESS) on the line below:
Xcode在下面的行上绘制错误(EXC_BAD_ACCESS):
//Bunch of functions that check for exact spots:
func checktop(value:Int)->(location:String,pattern:String) {
return ("top", checkFor(value, spots: [1,2,3])) //This line has error
}
func checkbottom(value:Int)->(location:String,pattern:String) {
return ("bottom", checkFor(value, spots: [7,8,9]))
}
func checkmidAcross(value:Int)->(location:String,pattern:String) {
return ("middle across", checkFor(value, spots: [4,5,6]))
}
func checkleft(value:Int)->(location:String,pattern:String) {
return ("left down", checkFor(value, spots: [1,4,7]))
}
func checkmidDown(value:Int)->(location:String,pattern:String) {
return ("middle down", checkFor(value, spots: [2,5,8]))
}
func checkright(value:Int)->(location:String,pattern:String) {
return ("right down", checkFor(value, spots: [3,6,9]))
}
func checkLRdiag(value:Int)->(location:String,pattern:String) {
return ("left-right diagonal", checkFor(value, spots: [1,5,9]))
}
func checkRLdiag(value:Int)->(location:String,pattern:String) {
return ("right-left diagonal", checkFor(value, spots: [3,5,7]))
}
Why would the app run just fine on the simulator but crash on the actual device? 为什么该应用程序可以在模拟器上正常运行,但在实际设备上崩溃? What's going wrong?
怎么了 Here is my checkFor method:
这是我的checkFor方法:
func checkFor(value:Int, spots:Int[])->(String) {
var conclusion = ""
for cell in spots {
if plays[cell] == value {
conclusion += "1"
}
else {
conclusion += "0"
}
}
return conclusion
}
func isOccupied(spot:Int)->(Bool) {
return Bool(plays[spot])
}
My App crashed with the same error on my device but not on the simulator. 我的应用程序崩溃了,但我的设备上却出现了相同的错误,但模拟器上却没有。 It turns out that my iOS 8 beta version did not match my Xcode beta version.
事实证明,我的iOS 8 beta版本与我的Xcode beta版本不匹配。 So I would check and make sure that your iOS 8 beta and Xcode beta are both on version 4 (the latest at the time of this writing).
因此,我将检查并确保您的iOS 8 beta和Xcode beta都在版本4(在撰写本文时为最新版本)上。 Also make sure that you completely reinstall the App, clean build folder etc.
另外,请确保您完全重新安装该应用程序,清理构建文件夹等。
This is of course assuming there is not an error with your code. 当然,这是假设您的代码没有错误。 Maybe you can post your checkFor method if the above does not work.
如果上述方法不起作用,也许可以发布您的checkFor方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.