postman99
postman99

Reputation: 23

Swift coreData context can't save

var error: NSError? = nil
return app.managedObjectContext!.save(&error)

It said "Cannot force unwrap value of non-optional type 'NSManagedObjectContext'"

And if i delete '!'

It said "'&' used with non-in out argument of type '()'"

And finally i delete '&'

It said "Argument passed to call that takes no arguments"

I feel hopeless.

Upvotes: 0

Views: 409

Answers (1)

Stuart Breckenridge
Stuart Breckenridge

Reputation: 1903

You need to use the new syntax:

do
    {
       try app.managedObjectContext.save()
    }  catch let error as NSError {
          print(error)
    }

Upvotes: 1

Related Questions