Correct way to update core-data

I'm trying to update my core data when a button gets pressed, it all looks fine when the app is running in one session, but when I restart the app, the update I made no longer exist. My code looks like this:

        if let indexPath ={
            let data = messageList[indexPath.row] as Messages
                if == true{
                println("Message already read")
           = true

Why does this happen? The change always get reverted when my app is being restarted.

Any suggestions would be appreciated.


You have to ensure, that you call save on the NSManagedObjectContext instance. There should be at least on call already defined in AppDelegate, but you might want to call it more often, e.g. when your app enters the background or on similar occasions.

For further reference, take a look at iOS Core Data when to save context?

You nedd to save NSManagedObjectContext before close your application.

For example: AppDelegate.swift

func applicationWillTerminate(application: UIApplication) {

This works only if you kill the app.

But if you want to save context after any change in NSManagedObject, you need to call

Need Your Help

Django Issue Template Does Not Exist at /deals/

django django-models django-forms django-views

I am new Django user. When I run program in Django I got this error please help.

WrapGrid Bug in Windows Store App

c# grid windows-store-apps

I tried to initialize WrapGrid in my application and I set its height and width and itemheight and itemwidth then i added childrens to it as a Border control

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.