Swift 2 ( executeFetchRequest ) : error handling

前端 未结 5 1903
我寻月下人不归
我寻月下人不归 2020-11-27 07:21

I got some issue with the code that I can\'t figure out. After I installed Xcode 7 beta and convert my swift code to Swift 2

Code:

o         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 08:06

    Try the code below

     override func viewWillAppear(animated: Bool) {
    
            let appDel:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
            let context = appDel.managedObjectContext
            let request = NSFetchRequest(entityName:"Users")
            do {
                let results = try context.executeFetchRequest(request)
    
                itemList = results as! [NSManagedObject]
    
    
            } catch let error as NSError {
                print("Could not fetch \(error), \(error.userInfo)")
            }
    
    
        }
    

提交回复
热议问题