간단한 앱은 추가 버튼이있는 탐색 컨트롤러에서 테이블보기로 시작됩니다. 추가 버튼은 텍스트 필드가있는 새보기를 가져오고 저장을 클릭하면 (업데이트 된) 테이블보기로 돌아갑니다. 나는 MOC를 저장하려고하면 내 문제는 아무 일도 발생하지 않습니다 및 디버거에서이 앱의 충돌 :Swift Managed Object Context 저장 실패
First name is: John
Last name is: Doe
Phone number is: 123456789
Before Save
(lldb)
및
libswiftCore.dylib`swift_dynamicCastClassUnconditional:
0x10c385860: pushq %rbp
0x10c385861: movq %rsp, %rbp
0x10c385864: testq %rdi, %rdi
0x10c385867: je 0x10c38589e ; swift_dynamicCastClassUnconditional + 62
0x10c385869: movabsq $-0x7fffffffffffffff, %rax
0x10c385873: testq %rax, %rdi
0x10c385876: jne 0x10c38589e ; swift_dynamicCastClassUnconditional + 62
0x10c385878: leaq 0xb52e9(%rip), %rax
0x10c38587f: movq (%rax), %rax
0x10c385882: andq (%rdi), %rax
0x10c385885: nopw %cs:(%rax,%rax)
0x10c385890: cmpq %rsi, %rax
0x10c385893: je 0x10c3858ad ; swift_dynamicCastClassUnconditional + 77
0x10c385895: movq 0x8(%rax), %rax
0x10c385899: testq %rax, %rax
0x10c38589c: jne 0x10c385890 ; swift_dynamicCastClassUnconditional + 48
0x10c38589e: leaq 0x36b7d(%rip), %rax ; "Swift dynamic cast failed"
0x10c3858a5: movq %rax, 0xb4c0c(%rip) ; gCRAnnotations + 8
0x10c3858ac: int3
****0x10c3858ad: movq %rdi, %rax
0x10c3858b0: popq %rbp
0x10c3858b1: retq
0x10c3858b2: nopw %cs:(%rax,%rax)
(****는에 충돌 라인입니다)
@IBAction func save() {
if let moc = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext {
employee = NSEntityDescription.insertNewObjectForEntityForName("Employee", inManagedObjectContext: moc) as Employee
contact = NSEntityDescription.insertNewObjectForEntityForName("Contact", inManagedObjectContext: moc) as Contact
employee.contact = contact
//println("First name is: " + employee.contact.firstName)
employee.contact.firstName = firstNameTextField.text
println("First name is: " + employee.contact.firstName)
employee.contact.lastName = lastNameTextField.text
println("Last name is: " + employee.contact.lastName)
employee.contact.phoneNumber = phoneNumberTextField.text
println("Phone number is: " + employee.contact.phoneNumber)
var e: NSError?
println("Before Save")
if moc.save(&e) != true {
println("After Save")
println("insert error: \(e!.localizedDescription)")
return
}
println("After Save")
// Execute the unwind segue and go back to the home screen
performSegueWithIdentifier("unwindToHomeScreen", sender: self)
}
UPDATE
을 이용하여야 : 여기 내 저장 기능입니다 EE 클래스 :
import Foundation
import CoreData
class Employee: NSManagedObject {
@NSManaged var wage: NSNumber
@NSManaged var socialInsuranceNumber: NSNumber
@NSManaged var contact: Contact
}
연락 클래스 :
import Foundation
import CoreData
class Contact: NSManagedObject {
@NSManaged var firstName: String
@NSManaged var lastName: String
@NSManaged var phoneNumber: String
@NSManaged var employee: NSManagedObject
}
직원 및 담당자 관리 대상 하위 클래스를 표시하십시오. –
이에 따라 편집 됨 – jjatie
Contact-Classic에 왜 employee 변수가 있습니까? 당신은 아무 데서도 그것을 설정하지 않습니다. 그것을 제거하고 다시 시도하십시오. – Christian