尝试构建一个笔记应用程序,Xcode 8,得到此错误

时间:2017-05-14 18:11:36

标签: xcode crash-reports

我一直在按照教程(过时的说法)和我尝试构建我的第一个笔记应用程序。不幸的是它甚至在运行之前就被终止了。任何帮助将非常感激。这是代码,最后是崩溃报告。干杯!

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        // Saves changes in the application's managed object context before the application terminates.
        self.saveContext()
    }

    // MARK: - Core Data stack

    lazy var persistentContainer: NSPersistentContainer = {
        /*
         The persistent container for the application. This implementation
         creates and returns a container, having loaded the store for the
         application to it. This property is optional since there are legitimate
         error conditions that could cause the creation of the store to fail.
        */
        let container = NSPersistentContainer(name: "ToDo")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()

    // MARK: - Core Data Saving support

    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }

}

这是我得到的崩溃报告

2017-05-14 21:04:58.079 ToDo[17123:3603269] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewCell'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010fcbdb0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010cb39141 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010fd26625 +[NSException raise:format:] + 197
    3   UIKit                               0x000000010d57fdde -[UITableView registerClass:forCellReuseIdentifier:] + 284
    4   ToDo                                0x000000010c5597db _TFC4ToDo14ViewController11viewDidLoadfT_T_ + 571
    5   ToDo                                0x000000010c5598e2 _TToFC4ToDo14ViewController11viewDidLoadfT_T_ + 34
    6   UIKit                               0x000000010d5c2cca -[UIViewController loadViewIfRequired] + 1235
    7   UIKit                               0x000000010d601b1c -[UINavigationController _layoutViewController:] + 56
    8   UIKit                               0x000000010d6023fa -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 466
    9   UIKit                               0x000000010d60256b -[UINavigationController _startTransition:fromViewController:toViewController:] + 127
    10  UIKit                               0x000000010d6036b3 -[UINavigationController _startDeferredTransitionIfNeeded:] + 843
    11  UIKit                               0x000000010d6047f1 -[UINavigationController __viewWillLayoutSubviews] + 58
    12  UIKit                               0x000000010d7f62bc -[UILayoutContainerView layoutSubviews] + 231
    13  UIKit                               0x000000010d4e320b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
    14  QuartzCore                          0x0000000112aa5904 -[CALayer layoutSublayers] + 146
    15  QuartzCore                          0x0000000112a99526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
    16  QuartzCore                          0x0000000112a993a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    17  QuartzCore                          0x0000000112a28e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    18  QuartzCore                          0x0000000112a55130 _ZN2CA11Transaction6commitEv + 468
    19  QuartzCore                          0x0000000112a55b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
    20  CoreFoundation                      0x000000010fc63717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    21  CoreFoundation                      0x000000010fc63687 __CFRunLoopDoObservers + 391
    22  CoreFoundation                      0x000000010fc48038 CFRunLoopRunSpecific + 440
    23  UIKit                               0x000000010d41a02f -[UIApplication _run] + 468
    24  UIKit                               0x000000010d4200d4 UIApplicationMain + 159
    25  ToDo                                0x000000010c55d077 main + 55
    26  libdyld.dylib                       0x0000000110c5d65d start + 1
    27  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

0 个答案:

没有答案