2015-08-13 70 views
-6
func fetchAndReload(){ 
      var error: NSError? 
      let results = coreDataStack.context.executeFetchRequest(fetchRequest, error: &error) as! [Venue]? 
    //fatal error: unexpectedly found nil while unwrapping an Optional value 
if let vs = results { 
      venues = vs 
     } else { 
      println("\(error),\(error?.userInfo)") 
     } 
     self.tableView.reloadData() 
    } 

//我不知道如何處理這個問題。IOS/Swift:致命錯誤:意外地發現零,同時展開一個可選值?

+0

我懷疑'fetchRequest'爲零。從你之前編輯的圖像看來,你正在從'fetchRequestTemplateForName'創建它,它會返回一個可選項。檢查你是否有正確的模板名稱。 – pbasdf

+0

非常感謝!我發現了你告訴我的錯誤。現在我糾正了模板名稱。謝謝! – heyanbai

回答

0

從文檔:

Write an optional binding for an if statement as follows:

if let constantName = someOptional { 
    statements 
} 

不像你的代碼

let constantName = someOptional 
if let cn = constantName { 
    statements 
} 

...

相關問題