Ho appena scaricato la nuova beta Xcode 7.0 e ho effettuato una migrazione da Swift 1.2 a Swift 2. La migrazione apparentemente non ha modificato l'intero codice, in effetti un metodo saveContext() che era bene fino getta 2 errori per la linea:Migrazione Swift 2 saveContext() in appDelegate
if moc.hasChanges && !moc.save() {
operatore binario '& &' non può essere applicato a due operandi Bool
e
chiamata può buttare, ma non è contrassegnata con 'provare' e l'errore non viene gestito
Il metodo è simile al seguente:
// MARK: - Core Data Saving support
func saveContext() {
if let moc = self.managedObjectContext {
var error: NSError? = nil
if moc.hasChanges && !moc.save() {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
}
}
Tutte le idee su come ottenerlo lavoro?
Grazie che è la risposta giusta, Inoltre, è necessario aggiungere un '' dopo managedObjectContext così la linea si presenta come:!!! 'Se managedObjectContext .hasChanges {' e 'provare managedObjectContext .save()' – kalafun
@kalafun No, in Xcode 7 il managedObjectContext non è opzionale. Postare aggiornamento sulla mia risposta – Ian
Questo è strano sto usando xcode 7 beta e ha generato un errore a causa del punto esclamativo mancante. Aspettando il tuo aggiornamento .. – kalafun