I have got a problem with saving several data from an array into one context.
I try the normal way for me to doing that but if I try to print the data there is only shown [, ]
in the console!
I don't get it?
Could you help me?
Here is my Code:
override func viewDidLoad() {
super.viewDidLoad()
let context: NSManagedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
let array = ["Hey", "there", "I", "am", "an", "example"]
let entityExample = NSEntityDescription.entityForName("Example", inManagedObjectContext: context)
var newItemExample = Example(entity: entityExample!, insertIntoManagedObjectContext: context)
for string in array {
newItemExample.string = string
println(newItemExample.string)
context.save(nil)
}
let fetchRequest = NSFetchRequest(entityName: "Example")
var dataExample = [Example]()
dataExample = context.executeFetchRequest(fetchRequest, error: nil) as [Example]
println(dataExample) }
What I am doing wrong and how it works?