che sto cercando di utilizzare NSPredicate a Swift per interrogare Core Data, ma getta un'EXC_BAD_ACCESS (Codice = 1, indirizzo = 0x1) di errore quando si tenta di eseguire cosa sto facendo di sbagliato?Swift NSPredicate gettando EXC_BAD_ACCESS (Codice = 1, indirizzo = 0x1) quando compounding dichiarazioni
Ecco il file in cui l'errore si verifica
class LevelsScreenModel : UIViewController {
func getWord(level: Int, section: Int) -> String
{
let fetchRequest = NSFetchRequest(entityName: "Words")
//This is the line where the error happens
fetchRequest.predicate = NSPredicate(format: "level = %@", level)
fetchRequest.predicate = NSPredicate(format: "section = %@", section)
let word = AppDelegate().managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) as [Words]
if(word.count > 1)
{
for words in word
{
println(words.word)
return words.word
}
}
return "ERROR"
}
}
L'errore finale era dovuto alla mancata possibilità di eseguire "AppDelegate()." per accedere a managedObjectContext. Invece questo codice ha funzionato per me "var appDel: AppDelegate = (UIApplication.sharedApplication(). Delegate come AppDelegate)" Spero che questo aiuti chiunque – Cesarg219