gpt4 book ai didi

ios - Xcode 中的应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 17:45:22 30 4
gpt4 key购买 nike

我是一名高中生,正在为学校项目创建一个简单的应用程序。这是我第一次使用 Swift 语言和 Xcode 创建应用程序。
每次我运行该应用程序时,它都会在打开之前崩溃。这是崩溃后显示的内容:

Error Message

这是代码:

import UIKit
import Foundation

class ViewController: UIViewController {

@IBOutlet weak var coffeeOutput: UILabel!
@IBOutlet weak var check1: UILabel!
let things = UserDefaults.standard

var coffeeShops = [0,0,0,0,0,0,0,0,0]

// 0 days: Int = 0
// 1 highland: Int = 0
// 2 starbucks: Int = 0
// 3 heine: Int = 0
// 4 quills: Int = 0
// 5 bean: Int = 0
// 6 sunergos: Int = 0
// 7 press: Int = 0
// 8 please: Int = 0



override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func highlands(sender: UIButton) {
things.set(things.integer(forKey: "highland")+1, forKey: "highland" )
things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.synchronize()
}

@IBAction func downtown(_:AnyObject) {

things.set(things.integer(forKey: "please")+1, forKey: "please" )
things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "press")+1, forKey: "press" )
things.synchronize()
}

@IBAction func germantown(_:AnyObject) {
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "bean")+1, forKey: "bean" )
things.set(things.integer(forKey: "sunergos")+1, forKey: "sunergos" )
things.synchronize()
}

@IBAction func school(_:AnyObject) {
things.set(things.integer(forKey: "quills")+1, forKey: "quills" )
things.synchronize()
}

@IBAction func homework(_:AnyObject) {

things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "quills")+1, forKey: "quills" )
things.set(things.integer(forKey: "sunergos")+1, forKey: "sunergos" )
things.synchronize()
}

@IBAction func meeting(_:AnyObject) {

things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "quills")+1, forKey: "quills" )
things.set(things.integer(forKey: "bean")+1, forKey: "bean" )
things.set(things.integer(forKey: "press")+1, forKey: "press" )
things.synchronize()
}

@IBAction func toGo(_:AnyObject) {

things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "bean")+1, forKey: "bean" )
things.set(things.integer(forKey: "sunergos")+1, forKey: "sunergos" )
things.set(things.integer(forKey: "please")+1, forKey: "please" )
things.synchronize()
}

@IBAction func hang(_:AnyObject) {

things.set(things.integer(forKey: "highland")+1, forKey: "highland" )
things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.synchronize()

}

@IBAction func morning(_:AnyObject) {

things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "bean")+1, forKey: "bean" )
things.set(things.integer(forKey: "sunergos")+1, forKey: "sunergos" )
things.set(things.integer(forKey: "press")+1, forKey: "press" )
things.synchronize()
}

@IBAction func midday(_:AnyObject) {
//0 2 3 4 6 7 8
things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "starbucks")+1, forKey: "starbucks" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.set(things.integer(forKey: "quills")+1, forKey: "quills" )
things.set(things.integer(forKey: "sunergos")+1, forKey: "sunergos" )
things.set(things.integer(forKey: "press")+1, forKey: "press" )
things.set(things.integer(forKey: "please")+1, forKey: "please" )
things.synchronize()
}

@IBAction func night(_:AnyObject) {
things.set(things.integer(forKey: "days")+1, forKey: "days" )
things.set(things.integer(forKey: "highland")+1, forKey: "highland" )
things.set(things.integer(forKey: "heine")+1, forKey: "heine" )
things.synchronize()
}

// 0 days: Int = 0
// 1 highland: Int = 0
// 2 starbucks: Int = 0
// 3 heine: Int = 0
// 4 quills: Int = 0
// 5 bean: Int = 0
// 6 sunergos: Int = 0
// 7 press: Int = 0
// 8 please: Int = 0

@IBAction func computeShop(_:AnyObject) {
var max = things.integer(forKey: "days")
var maxKey = "days"
for element in UserDefaults.standard.dictionaryRepresentation().keys.elements{
if(things.integer(forKey: element)>max){
max = things.integer(forKey: element)
maxKey = element
}
}
self.coffeeOutput.text = maxKey

for element in UserDefaults.standard.dictionaryRepresentation().keys.elements{
things.set(0,forKey: element)
things.synchronize()
}


}
}

这是堆栈跟踪:
{

2017-04-13 12:13:04.411 按钮[95215:59212987]-[ NSCFNumber _getCString:maxLength:encoding:]:无法识别的选择器发送到实例 0xb000000000000003
2017-04-13 12:13:04.574 按钮 [95215:59212987] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFNumber _getCString:maxLength:encoding:]:无法识别的选择器发送到实例 0xb000000000000003”
*** 首先抛出调用堆栈:
(
0 核心基础 0x000000010b4f4d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010af5621e objc_exception_throw + 48
2核心基础0x000000010b564f04-[NSObject(NSObject)不识别选择器:]+132
3 核心基础 0x000000010b47a005 ___forwarding_
+ 1013
4 核心基础 0x000000010b479b88 _CF_forwarding_prep_0 + 120
5 核心基础 0x000000010b42e89b CFStringGetCString + 171
6 CoreFoundation 0x000000010b43e77d CFLocaleCreateCanonicalLocaleIdentifierFromString + 77
7 核心基础 0x000000010b43e327 _CFLocaleCopyCurrentGuts + 487
8 核心基础 0x000000010b43e109 +[NSLocale currentLocale] + 9
9 基础 0x000000010aa19376 -[NSUserDefaults(NSUserDefaults) 初始化] + 1637
10 基础 0x000000010aa18cb5 +[NSUserDefaults(NSUserDefaults)standardUserDefaults] + 81
11 UIKit 0x000000010b9438df ___UIApplicationMainPreparations_block_invoke_2 + 53
12 libdispatch.dylib 0x000000010eb7d978 _dispatch_call_block_and_release + 12
13 libdispatch.dylib 0x000000010eba70cd _dispatch_client_callout + 8
14 libdispatch.dylib 0x000000010eb8865f _dispatch_root_queue_drain + 1450
15 libdispatch.dylib 0x000000010eb88059 _dispatch_worker_thread3 + 123
16 libsystem_pthread.dylib 0x000000010ef56736 _pthread_wqthread + 1299
17 libsystem_pthread.dylib 0x000000010ef56211 start_wqthread + 13
)
libc++abi.dylib:以 NSException 类型的未捕获异常终止
(lldb)
}

知道问题是什么吗?

最佳答案

  • 检查您的 xib 文件的文件所有者
  • 检查与 View Controller 的连接(导出和操作)

  • 修复这些后,清理构建(cmd + shift + k)并重新运行它。

    如果它仍然崩溃,
    在所有类中设置断点,并找出它崩溃的确切位置。请给我们一些额外的信息,我们会尽力帮助更多

    注意:同步不是必需的

    关于ios - Xcode 中的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43351686/

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