我在将数组中的多个数据保存到一个上下文中时遇到了问题。我尝试了正常的方式来执行此操作,但是如果我尝试打印数据,则只会[, ]
在控制台中显示!我不明白?
你可以帮帮我吗?
这是我的代码:
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) }
我做错了什么以及它是如何工作的?