Swift项目与线程1崩溃:EXC_BAD_ACCESS(代码= 1,地址= 0x0)

Sam*_*amG 18 ios swift

它看起来像是一个糟糕的内存访问,就像尝试访问不存在的对象一样.我尝试使用NSZombie看看是否有什么东西出现,据我所知,没有做到.它在app委托的声明中崩溃了.

AppDelegate.swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]) -> Bool
{
    // Override point for customization after app launches
    Parse.setApplicationId("removed on purpose", clientKey: "removed on purpose")
    PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
    PFFacebookUtils.initializeFacebook()

    return true
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool
{
    return FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication, withSession: PFFacebookUtils.session())

}

func applicationDidBecomeActive(application: UIApplication)
{
    FBAppCall.handleDidBecomeActiveWithSession(PFFacebookUtils.session())
}

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 throttle down OpenGL ES frame rates. 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 applicationWillTerminate(application: UIApplication)
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}
Run Code Online (Sandbox Code Playgroud)

DashboardViewController.swift

import UIKit

class DashboardViewController: UIViewController
{
override func viewDidLoad()
{
    super.viewDidLoad()
    // Do any additional setup after loading the view
}

}
Run Code Online (Sandbox Code Playgroud)

使用断点我已经确定它甚至没有通过app委托的类声明.我尝试检查Main.storyboard文件中的所有类,以确保所有内容都正确链接,据我所知.

Kla*_*aas 14

我今天遇到了同样的问题.从Xcode 6 beta 6开始,自动完成表明:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]) -> Bool {}
Run Code Online (Sandbox Code Playgroud)

这在启动时崩溃,出现EXC_BAD_ACCESS和空白屏幕.

一旦!添加到最后一个参数,一切正常:

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]!) -> Bool {}
Run Code Online (Sandbox Code Playgroud)

当前的文档!也缺少:

optional func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]) -> Bool
Run Code Online (Sandbox Code Playgroud)

  • Xcode 7包含一个`?`而不是`!`,我仍然得到这个例外. (3认同)