이 소개 자습서를 this tutorial에 따라 수행 중이며 Core Data에 완전히 익숙하지 않습니다.NSEntityDescription.insertNewObject Swift에서 크래시가 발생하는 함수 3
다음은 오류를 생성하는 클래스입니다 (단, 오류로 인해 sigabrt가있는 AppDelegate의 첫 번째 행으로 이동 함) "let newUser"로 시작하는 줄은 내가 주석을 달면 오류가 사라지기 때문에 오류가 발생하는 것 같습니다. 에서. 아무도 YouTube 동영상의 코멘트 섹션 위의 아직에이 오류에 대해 게시되지 않았기 때문에
@IBAction func btnSave(){
let appDel:AppDelegate = (UIApplication.shared().delegate as! AppDelegate)
let context:NSManagedObjectContext = appDel.persistentContainer.viewContext
let newUser = NSEntityDescription.insertNewObject(forEntityName: "Users", into: context) as NSManagedObject
do {
try context.save()
} catch {}
print("Object Saved.")
}
This problem looks similar, but the answer is confusing to me and seems a bit overcomplicated
, 나는이 때문에 스위프트 3의 변화에 오류 가정 (때문에 또 다른 오류가 발생했습니다 코멘트에 기록 된 Swift 2의 변화)
도움을 주시면 대단히 감사하겠습니다.
frame #0: 0x00000001067cbf06 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00000001068ec4ec libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x000000010651e0b3 libsystem_c.dylib`abort + 129
frame #3: 0x00000001067ea43a libc++abi.dylib`abort_message + 266
frame #4: 0x000000010680ea9f libc++abi.dylib`default_terminate_handler() + 267
frame #5: 0x00000001055be59f libobjc.A.dylib`_objc_terminate() + 103
frame #6: 0x000000010680bc09 libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #7: 0x000000010680b894 libc++abi.dylib`__cxa_rethrow + 99
frame #8: 0x00000001055be4b7 libobjc.A.dylib`objc_exception_rethrow + 40
frame #9: 0x00000001030f7bf1 CoreFoundation`CFRunLoopRunSpecific + 433
frame #10: 0x000000010850ea48 GraphicsServices`GSEventRunModal + 161
frame #11: 0x0000000103b30e8b UIKit`UIApplicationMain + 159
* frame #12: 0x0000000102b5dc6f CoreDataYoutube`main + 111 at AppDelegate.swift:5
frame #13: 0x00000001064726bd libdyld.dylib`start + 1
유용하지 않은 부분을 표시하고 있습니다. 이 오류는 ObjC 예외가 발생하여 발생하므로 오류를 설명하는 게시 된 스택 추적 위에 콘솔 출력이 있어야합니다. – rickster
스위프트 3에서는'UIApplication.shared.delegate' (괄호 안 함) – vadian
@vadian 방금 Xcode 8.1로 업데이트했고 언급 한 변경 작업을 수행해야했습니다. 그러나 업데이트 된 내용은 내 이전 솔루션 (" 대답 ") 이제는 더 이상 작동하지 않으며, 나는 왜 그런지 모른다 ... – PlateReverb