更新到XCode 7后,iOS模拟器卡在启动页面上

时间:2015-09-23 04:01:28

标签: ios swift2 xcode7

我从Xcode 6更新到Xcode 7并将我的代码从swift 1.2更新为swift 2.0。当我运行项目时,没有编译时错误,只有警告,并且构建成功。我遇到的问题是main.storyboard没有加载。通过这个我的意思是模拟器中显示的所有内容都是启动页面,初始视图控制器永远不会放入层次结构中(我相信)。当我将我的代码更新为swift 2.0时,我手动更新了AppDelegate,这是我没想到的,也就是为什么我认为文件可能有问题。我也得到一个线程1:EXC_BAD_ACCESS(code = 2 ...)错误,我理解为一个递归错误,但不明白如何解决问题。

我尝试过的事情

  • 重新安装Xcode 7
  • 使用模拟器8.4代替9.0
  • 更新为上一个快速语法(编辑 - >转换 - >转换为最新的Swift语法)
  • 这是我的AppDelegate文件

    import UIKit
    import CoreData
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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 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 inactive 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 applicationDocumentsDirectory: NSURL = {
        // The directory the application uses to store the Core Data store file. This code uses a directory named "com.wt9t.BaseballsInsightVersionBeta" in the application's documents Application Support directory.
        let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
        return urls[urls.count-1]
    }()
    
    lazy var managedObjectModel: NSManagedObjectModel = {
        // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
        let modelURL = NSBundle.mainBundle().URLForResource("BaseballsInsightVersionBeta", withExtension: "momd")!
        return NSManagedObjectModel(contentsOfURL: modelURL)!
    }()
    
    lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
        // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added 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.
        // Create the coordinator and store
        var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
        let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("BaseballsInsightVersionBeta.sqlite")
        var error: NSError? = nil
        var failureReason = "There was an error creating or loading the application's saved data."
        let mOptions = [NSMigratePersistentStoresAutomaticallyOption: true,
            NSInferMappingModelAutomaticallyOption: true]
        do {
            try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
        } catch let error as NSError {
            print(error.localizedDescription)
    
        }
    
        return coordinator
    }()
    
    lazy var managedObjectContext: NSManagedObjectContext? = {
        // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
        let coordinator = self.persistentStoreCoordinator
        if coordinator == nil {
            return nil
        }
        var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType)
        managedObjectContext.persistentStoreCoordinator = coordinator
        return managedObjectContext
    }()
    
    // MARK: - Core Data Saving support
    
    func saveContext () {
        if managedObjectContext!.hasChanges {
            do {
                try managedObjectContext!.save()
            } catch {
                // Replace this implementation with code to handle the error appropriately.
                // abort() 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
                NSLog("Unresolved error \(nserror), \(nserror.userInfo)")
                abort()
            }
        }
    }
    
    }
    

    此外,我还包括名为MainVC的初始视图控制器

    import UIKit
    import CoreData
    import Foundation
    import SystemConfiguration
    
    class MainVC: UIViewController {
    
    @IBOutlet var chartCountTextView: UITextView!
    let cdao = CoreDataRequests()
    
    var chartsCompleted:Array<String> = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print("Viewdidload finished")
        self.view.backgroundColor = UIColor.darkGrayColor()
    
        let count = cdao.getChartCountInQueue()
    
        if(count != 0)
        {
    
            chartCountTextView.text = "\(count) charts have yet to be uploaded, click Chart Queue to start the process"
        }
        else
        {
            chartCountTextView.text = ""
        }
    
        chartCountTextView.backgroundColor = UIColor.clearColor()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(animated: Bool) {
        let email = NSUserDefaults.standardUserDefaults().stringForKey("userEmail")
        let password = NSUserDefaults.standardUserDefaults().stringForKey("userPassword")
    
        if(email == nil || password == nil)
        {
            self.performSegueWithIdentifier("login", sender: self)
        }
    }
    }
    

    0 个答案:

    没有答案