2017-04-11 29 views
-1

私は学校プロジェクトのためのシンプルなアプリケーションを作成している高校生です。これは、アプリを作成し、Swift言語を使用し、Xcodeを使用して初めてのことです。 アプリを実行するたびに、アプリが開く前にクラッシュします。これは、クラッシュ後に示されているものである。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年4月13日12時13: 04454ボタン[95215:59212987] - [NSCFNumber _getCString:maxLength:encoding:]:インスタンスに送信された認識できないセレクタ0xb000000000000003 2017-04-13 12:13:04.574ボタン[95215:59212987]アプリによるキャッチされない例外 'NSInvalidArgumentException'、理由: ' - [__ NSCFNumber _getCString:maxLengthの:符号化:]:認識されないセレクターインスタンス0xb000000000000003に送ら' ***まずスローコールスタック: ( 0 CoreFoundationの0x000000010b4f4d4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010af5621e objc_exception_throw + 48 2 CoreFoundationの0x000000010b564f04 - [NSObjectの(NSObjectの)doesNotRecognizeSelector:] + 132 3 CoreFoundationの0x000000010b47a005 ___forwarding_ + 1013 4 CoreFoundationの0x000000010b479b88 _CF_forwarding_prep_0 + 120 5 CoreFoundationの0x000000010b42e89b CFStringGetCString + 171 6 CoreFoundationの0x000000010b43e77d CFLocaleCreateCanonicalLocaleIdentifierFromString + 77 7 CoreFoundationの0x000000010b43e327 _CFLocaleCopyCurrentGuts + 487 8 CoreFoundationの0x000000010b43e109 + [NSLocale currentLocale] + 9 9ファンデーション0x000000010aa19376 - [NSUserDefaults(NSUserDefaults)INIT] + 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 1 5 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)

}のキャッチされない例外で終わります

問題は何ですか?

+1

必要はありませんが、synchronize' 'にそれらの不要な呼び出しのすべてを取り除く:私たちにいくつかの余分な情報を与えてください、我々はより多くの

ノートを助けるためにしようとするだろう。 – rmaddy

+0

あなたのクラッシュは、ストーリーボードと並んでいないIBOutlet/IBActionと関係があると思います。あなたはおそらくどこにも行かないストーリーボードで開始されたものを持っているでしょう。 –

+1

クラッシュをデバッグする方法については、http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1を参照してください。 – rmaddy

答えて

0

ViewDidLoadメソッドでブレークポイントを指定します。たとえそこに来る前にクラッシュしても。その後、ストーリーボードの接続を確認してください。あなたはいくつかの接続を削除している可能性があり、ストーリーボードはまだそれを探しているかもしれません。

+0

これは実際に問題を解決するものではないので、コメントを書く必要があります。 – rmaddy

1
  1. ビルド(CMD +シフト+ k)を清掃し、それらを固定した後
  2. あなたのXIBファイルのファイルの所有者を確認し、あなたのビューコントローラ(アウトレットとアクション)への接続を確認し

とそれを再実行します。

それはまだ、すべてのクラスで、 プット・ブレーク・ポイントをクラッシュし、それがクラッシュした場所を正確に見つける場合。同期あなたのクラッシュとは関係のない

+0

私は初心者ですので、私のために物事を綴る必要があります。申し訳ありません。私のアプリケーションの各ボタンに.xibファイルがありますか?もしそうなら、それらのカスタムクラスはすべてUIButtonであり、変更することはできません。 – Sidganz1234

+0

は、スタックトレースです – Sidganz1234

+0

iOSの画面は、以下の方法によって開発することができます:プログラム 1.ここ –

関連する問題