我一直有致命的错误:
在解包可选值时意外地发现了nil。
我知道错误的一般意义,但是我不知道我做错了什么导致它。
我已将问题缩小到令人放松的心态:
import UIKit
import Foundation
import CoreData
import Alamofire
import FastImageCache
import SwiftyJSON
class ViewControllerTabBar: UITabBarController {
var shouldLogin = false
var user: User? {
didSet {
if user != nil {
} else {
shouldLogin = true
}
}
}
var nextURLRequest: NSURLRequest?
var coreDataStack: CoreDataStack!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
UITabBar.appearance().tintColor = UIColor(red: 99/255, green: 222/255, blue: 154/255, alpha: 1)
if let fetchRequest = coreDataStack.model.fetchRequestTemplateForName("UserFetchRequest") {
let results = try! coreDataStack.context.executeFetchRequest(fetchRequest) as! [User]
user = results.first
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if shouldLogin {
performSegueWithIdentifier("login", sender: self)
shouldLogin = false
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func unwindToPhotoBrowser (segue : UIStoryboardSegue) {
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "login" && segue.destinationViewController.isKindOfClass(UINavigationController.classForCoder()) {
let navigationController = segue.destinationViewController as! UINavigationController
if let oauthLoginViewController = navigationController.topViewController as? OauthLoginViewController {
oauthLoginViewController.coreDataStack = coreDataStack
}
if self.user != nil {
coreDataStack.context.deleteObject(user!)
coreDataStack.saveContext()
}
}
}
}
问题似乎与
有关@IBAction func unwindToPhotoBrowser (segue : UIStoryboardSegue) {
}
我已经仔细检查了我的标识符和故事板中的连接。我有一个类似的项目,使用类似的登录设置,该项目似乎在删除此IBAction时得到相同的错误,这就是为什么我认为这可能是问题。当我在Find Navigator中搜索动作时,它并没有显示出" M"旁边的图标,而我的其他项目就是。