+1 Adam Streamer · February 11, 2015
Hello, I love your tutorials on YouTube about Swift developing. You are teaching very simple and this kind of tutorials are great for beginners.

I would like ask you for make a video or answer here how to use Core Data. Just simple lines how to add, read, delete and update rows. 

I can't find it.  Tutorials on YouTube are too much complicated for me. I need simple code how to use it when I have defined Entities in .xcdatamodeld

Thanks, best regards

Post a Reply


Oldest  Newest  Rating
0 Adam Streamer · February 13, 2015
all what i found in few video tutorials:

//1 CoreData
let appDel = UIApplication.sharedApplication().delegate as AppDelegate
let context = appDel.managedObjectContext!

//2 CRUD
// .create
let entity =  NSEntityDescription.entityForName("ENTITY_NAME", inManagedObjectContext: context)
var newItem = NSManagedObject(entity: entity!, insertIntoManagedObjectContext:context) as Serduszko
newItem.attribute1 = value1
newItem.attribute2 = value2

// .read
var error: NSError?
let fetchRequest = NSFetchRequest(entityName:"ENTITY_NAME")
let fetchedResults = context.executeFetchRequest(fetchRequest, error: &error) as [NSManagedObject]?

if let results = fetchedResults {
    self.list = results
else {
    println("Could not fetch \(error), \(error!.userInfo)")

// .update

// .delete
  • 1

iOS Development / Swift


This forum is for questions, comments, and general discussion about iOS Development and Swift.

Bucky Roberts Administrator