小编Jor*_*mez的帖子

条件绑定的初始化程序必须具有可选类型,而不是'NSManagedObjectContext

我收到此错误消息:"条件绑定的初始化程序必须具有可选类型,而不是'NSManagedObjectContext".

我不知道如何解决这个错误.我认为错误在于"if let".

  if  let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext  {
        restaurant = NSEntityDescription.insertNewObjectForEntityForName("Restaurant",
            inManagedObjectContext: managedObjectContext) as! Restaurant
        restaurant.name = nameTextField.text
        restaurant.type = typeTextField.text
        restaurant.location = locationTextField.text
        restaurant.image = UIImagePNGRepresentation(imageView.image!)
        restaurant.isVisited = isVisited
        //restaurant.isVisited = NSNumber.convertFromBooleanLiteral(isVisited)

        var e: NSError?
        if managedObjectContext.save() != true {
            print("insert error: \(e!.localizedDescription)")
            return
        }
    }
Run Code Online (Sandbox Code Playgroud)

xcode ios swift

3
推荐指数
1
解决办法
3283
查看次数

使用performSegueWithIdentifier()将撇号添加到标识符

我想从一个viewController跳到另一个.我一直在使用performSegueWithIdentifier,它适用于所有viewControllers期望的一个.每次应用程序尝试执行segue时都会显示以下错误:

2016-08-21 15:04:29.170入职[44226:2490189]***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'Receiver()没有标识符'gogo''的segue

我在segue中的标识符是"gogo".在我的代码中我使用:

self.performSegueWithIdentifier("gogo", sender: self)
Run Code Online (Sandbox Code Playgroud)

如果你仔细查看错误消息,我注意到Xcode在标识符中添加了一个撇号.打印'gogo''而不是'gogo'.为什么会这样?

xcode ios segue swift

0
推荐指数
1
解决办法
78
查看次数

标签 统计

ios ×2

swift ×2

xcode ×2

segue ×1