2014-09-25 64 views
-2

我是新來的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) 

回答

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!") 
}