Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift project crashing with Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x0)

Tags:

It looks like a bad memory access, like trying to access an object that does not exist. I tried using NSZombie to see if something came up, as far as I could tell nothing did. It is crashing at the declaration for the app delegate.

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:. }   } 

DashboardViewController.swift

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

Using breakpoints I have determined that it is not even getting past the class declaration for the app delegate. I tried checking all of the classes in my Main.storyboard file as well to make sure everything was linked properly, again as far as I can tell it is.

like image 301
SamG Avatar asked Aug 17 '14 21:08

SamG


1 Answers

I ran into the same issue today. As of Xcode 6 beta 6 the auto complete suggests:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]) -> Bool {} 

This crashes at startup with an EXC_BAD_ACCESS and a blank screen.

As soon as an ! is added to the last argument, everything works fine:

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]!) -> Bool {} 

In current documentation the ! is missing as well:

optional func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]) -> Bool 
like image 168
Klaas Avatar answered Sep 21 '22 15:09

Klaas