I have an Entity called "Friend". Attributes are name and age. I implemented the bridge because the NSManagedObject class for Friend has .h and .m files. My code for storing data:
var err: NSError? var delegate:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate var friend:Friend = Friend(entity: NSEntityDescription.entityForName("Friend", inManagedObjectContext: delegate.managedObjectContext), insertIntoManagedObjectContext: delegate.managedObjectContext) friend.friendName = "Mani" friend.friendAge = "23" delegate.managedObjectContext.save(&err)
My code to retrieve data
var result: Array = delegate.managedObjectContext.executeFetchRequest(NSFetchRequest(entityName: "Friend"), error: &err) println("reslut \(result)")
Therefore, when I return, it gives a result with data. But it is not saved forever .. If I leave and run the application, then the previous data has disappeared. Tell me what the problem is with my code ...
Here is an example project https://github.com/rnystrom/Swift-CoreData I got it from Github .. this project also has the same problem.
ios8 swift xcode6 core-data
Mani murugan
source share