无法使用swift在核心数据中存储用户数据

时间:2014-09-25 05:22:09

标签: ios swift

我是ios编程的新手所以请查看这些错误并帮助我

libswiftCore.dylib`swift_dynamicCastObjCClassUnconditional:
0x238afa0:  pushl  %ebp
0x238afa1:  movl   %esp, %ebp
0x238afa3:  pushl  %edi
0x238afa4:  pushl  %esi
0x238afa5:  subl   $0x10, %esp
0x238afa8:  calll  0x238afad                 ; swift_dynamicCastObjCClassUnconditional + 13
0x238afad:  popl   %esi
0x238afae:  movl   0x8(%ebp), %edi
0x238afb1:  xorl   %eax, %eax
0x238afb3:  testl  %edi, %edi
0x238afb5:  je     0x238afd6                 ; swift_dynamicCastObjCClassUnconditional + 54
0x238afb7:  movl   0xc(%ebp), %eax
0x238afba:  movl   0x5587f(%esi), %ecx
0x238afc0:  movl   %eax, 0x8(%esp)
0x238afc4:  movl   %ecx, 0x4(%esp)
0x238afc8:  movl   %edi, (%esp)
0x238afcb:  calll  0x238dc6a                 ; symbol stub for: objc_msgSend
0x238afd0:  testb  %al, %al
0x238afd2:  movl   %edi, %eax
0x238afd4:  je     0x238afdd                 ; swift_dynamicCastObjCClassUnconditional + 61
0x238afd6:  addl   $0x10, %esp
0x238afd9:  popl   %esi
0x238afda:  popl   %edi
0x238afdb:  popl   %ebp
0x238afdc:  retl   
0x238afdd:  leal   0xbe05(%esi), %eax
0x238afe3:  movl   0x490a3(%esi), %ecx
0x238afe9:  movl   %eax, 0x8(%ecx)
0x238afec:  movl   $0x0, 0xc(%ecx)
0x238aff3:  int3   
0x238aff4:  nopw   %cs:(%eax,%eax)

我正在使用此代码

var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var newUser = NSEntityDescription.insertNewObjectForEntityForName("User", inManagedObjectContext: context) as NSManagedObjectContext

newUser.setValue("true", forKey: "isLoggedin")
context.save(nil)

1 个答案:

答案 0 :(得分:0)

很难确定您的问题,看看发布的跟踪。但我注意到你没有创建一个新的User对象来保存。而不是使用setValue,请尝试此操作。

let appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
let context:NSManagedObjectContext = appDel.managedObjectContext!
let entityDescripition = NSEntityDescription.entityForName("User", inManagedObjectContext: context)
let newUser = User(entity: entityDescripition!, insertIntoManagedObjectContext: context)

newUser.isLoggedin = true

var err: NSError?
if context?.save(&err) == false {
    println(err!.localizedDescription)
} else {
    println("Data saved successfully!")
}