Swift 试图用核心数据保存值,但遇到错误:“0”;libc++;abi.dylib:以NSException类型的未捕获异常终止;
无法保存用户输入而不执行此操作,调试器说我正在成功地将用户输入存储在变量中,但在启动保存操作后,它崩溃并将我指向Swift 试图用核心数据保存值,但遇到错误:“0”;libc++;abi.dylib:以NSException类型的未捕获异常终止;,swift,xcode,core-data,optional,Swift,Xcode,Core Data,Optional,无法保存用户输入而不执行此操作,调试器说我正在成功地将用户输入存储在变量中,但在启动保存操作后,它崩溃并将我指向 Class App Delegate: with "Thread 1 signal SIGABRT" error 命令行中显示: "libc++abi.dylib: terminating with uncaught exception of type NSException" 下面是保存操作 let saveAction = UIAlertAction(title: "Sa
Class App Delegate: with "Thread 1 signal SIGABRT" error
命令行中显示:
"libc++abi.dylib: terminating with uncaught exception of type NSException"
下面是保存操作
let saveAction = UIAlertAction(title: "Save", style: .default)
{ [unowned self] action in
// find textfield's text (name) guard let way to get unwrap value otherwise return early*/
guard let textField1 = alert.textFields?.first,
let nameToSave = textField1.text else
{
return
}
/*find textfield's text (size) guard let way to get unwrap value otherwise return early*/
guard let textField2 = alert.textFields?[1],
let sizeToSave = textField2.text else
{
return
}
// find textfield's text (contact) guard let way to get unwrap value otherwise return early*/
guard let textField3 = alert.textFields?[2],
let contactToSave = textField3.text else
{
return
}
guard let textField4 = alert.textFields?[3],
let preferenceToSave = textField4.text else
{
return
}
//call save method by passing info
self.save(name: nameToSave, size: Int16(sizeToSave)!, contact: Int32((contactToSave))!, seating: preferenceToSave)
self.tableView.reloadData()
}
这是上面第二行到最后一行调用的save函数
func save(name: String, size: Int16, contact: Int32, seating: String ) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Party", in: managedContext)!
let party = NSManagedObject(entity: entity,
insertInto: managedContext)
party.setValue(name, forKeyPath: "name")
party.setValue(size, forKeyPath: "size")
party.setValue(contact, forKeyPath: "contact")
party.setValue(seating, forKeyPath: "seating")
do {
try managedContext.save()
parties.append(party)
tableView.reloadData()
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
}
如果需要提供任何其他帮助,请让我知道
完整命令行:
2019-04-24 14:34:41.738429-0400 WaitUp[25353:1273717] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/alexanderhoinville/Library/Developer/CoreSimulator/Devices/5623D759-E945-4844-9D55-CE708330A41F/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-04-24 14:34:41.739724-0400 WaitUp[25353:1273717] [MC] Reading from private effective user settings.
2019-04-24 14:34:51.330 WaitUp[25353:1273717] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UITableView.m:8174
2019-04-24 14:34:51.366 WaitUp[25353:1273717] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7ff5ef835800; frame = (0 64; 375 603); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x60000005fa40>; layer = <CALayer: 0x60800022b2a0>; contentOffset: {0, -64}; contentSize: {375, 44}>) failed to obtain a cell from its dataSource (<WaitUp.ViewController: 0x7ff5eec0e1d0>)'
*** First throw call stack:
(
0 CoreFoundation 0x000000010709fb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000104242141 objc_exception_throw + 48
2 CoreFoundation 0x00000001070a3cf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000103ddc3b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000104c82fcf -[UITableView _configureCellForDisplay:forIndexPath:] + 230
5 UIKit 0x0000000104c8e7b8 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 836
6 UIKit 0x0000000104c8e9a8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
7 UIKit 0x0000000104c632e9 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
8 UIKit 0x0000000104c9797c -[UITableView _performWithCachedTraitCollection:] + 111
9 UIKit 0x0000000104c7eb2a -[UITableView layoutSubviews] + 233
10 UIKit 0x0000000104be520b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
11 QuartzCore 0x0000000109e19904 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x0000000109e0d526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
13 QuartzCore 0x0000000109e0d3a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000109d9ce92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
15 QuartzCore 0x0000000109dc9130 _ZN2CA11Transaction6commitEv + 468
16 QuartzCore 0x0000000109dc9b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
17 CoreFoundation 0x0000000107045717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x0000000107045687 __CFRunLoopDoObservers + 391
19 CoreFoundation 0x000000010702a720 __CFRunLoopRun + 1200
20 CoreFoundation 0x000000010702a016 CFRunLoopRunSpecific + 406
21 GraphicsServices 0x0000000108f5aa24 GSEventRunModal + 62
22 UIKit 0x0000000104b220d4 UIApplicationMain + 159
23 WaitUp 0x000000010383ed57 main + 55
24 libdyld.dylib 0x0000000107fd965d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
2019-04-24 14:34:41.738429-0400等待[25353:1273717][MC]systemgroup.com.apple.configurationprofiles路径为/Users/alexanderhoinville/Library/Developer/CoreSimulator/Devices/5623D759-E945-4844-9D55-CE708330A41F/data/Containers/Shared/systemgroup/systemgroup.com.apple.configurationprofiles
2019-04-24 14:34:41.739724-0400等待[25353:1273717][MC]从私人有效用户设置读取。
2019-04-24 14:34:51.330等待[25353:1273717]***在-[UITableView\u configureCellForDisplay:forIndexPath:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit\u Sim/UIKit-3600.7.47/UITableView.m:8174中断言失败
2019-04-24 14:34:51.366等待[25353:1273717]***由于未捕获的异常“nsInternalInconsistenceException”而终止应用程序,原因:“UITableView()未能从其数据源()获取单元格”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x000000010709fb0b例外预处理+171
1 libobjc.A.dylib 0x00000001042141 objc_异常_抛出+48
2 CoreFoundation 0x00000001070a3cf2+[NSException raise:格式:参数:][98
3基金会0x000 000 0103DDC3B6- [ NSRealStutsHuffer-HooRealRuleIn方法:对象:文件:文件号:描述:] + 193
4 UIKit 0x0000000104c82fcf-[UITableView\u配置CellForDisplay:forIndexPath:+230
5 UIKit 0x0000000104c8e7b8-[UITableView\u createPreparedCellForGlobalRow:withIndexPath:willDisplay:+836
6 UIKit 0x0000000104c8e9a8-[UITableView\u createPreparedCellForGlobalRow:将显示:][74
7 UIKit 0x0000000104c632e9-[UITableView\u updateVisibleCellsNow:isRecursive:+2845
8 UIKit 0x0000000104c9797c-[UITableView\u性能与CachedTraitCollection:+111
9 UIKit 0x0000000104c7eb2a-[UITableView布局子视图]+233
10 UIKit 0x0000000104be520b-[UIView(CALayerDelegate)布局层的子层:+1268
11夸脱核心0x0000000109e19904-[CALayer布局子层]+146
12夸脱核心0x0000000109e0d526 ZN2CA516层布局U如果需要PNS 11交易+370
13夸脱核心0x0000000109e0d3a0\u ZN2CA58层布局\u和\u显示\u如果需要\u交易+24
14 QuartzCore 0x0000000109d9ce92_ZN2CA7Context18提交交易PNS_11交易+294
15夸脱核心0x0000000109dc9130_Zn2Ca11交易承诺+468
16 QuartzCore 0x0000000109dc9b37_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv+115
17 CoreFoundation 0x0000000107045717\uuuu CFRUNLOOP\u正在调用\u OUT\u来调用\u OBSERVER\u CALLBACK\u函数\uuu+23
18 CoreFoundation 0x0000000107045687\uu cfrunloopdoobserver+391
19 CoreFoundation 0x000000010702a720\uuuu CFRunLoopRun+1200
20 CoreFoundation 0x000000010702a016 CFRunLoopRunSpecific+406
21图形服务0x0000000108f5aa24 GSEventRunModal+62
22 UIKit 0x0000000104b220d4 UIApplicationMain+159
23等待0x000000010383ed57主+55
24 libdyld.dylib 0x0000000107fd965d开始+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)
能否显示完整的错误消息。您应该有一个“以NSUncaughtException类型的未捕获异常终止”(注意“NSUncaughtException”与“NSException”的比较。在帖子中添加了完整的日志,感谢您的快速回复!我找不到NSUncought的行,只有NSException原谅我,我的tableview出现了问题,xcode让我无法将我指向其他地方。对于任何需要此功能的人,我只需将UITableViewDataSource也添加到类定义中。无论如何,谢谢!这也是要指出的此时,您会在崩溃日志/消息中找到一些信息,但您没有得到有趣的部分:“由于未捕获的异常而终止应用程序'nsInternalInconsistencException',原因:'UITableView(;layer=;contentOffset:{0,-64};contentSize:{375,44}>)无法从其数据源()获取单元格();)您能否显示完整的错误消息。您应该有一个“以NSUncaughtException类型的未捕获异常终止”(注意“NSUncaughtException”与“NSException”的比较。在帖子中添加了完整的日志,感谢您的快速回复!我找不到NSUncought的行,只有NSException原谅我,我的tableview出现了问题,xcode让我无法将我指向其他地方。对于任何需要此功能的人,我只需将UITableViewDataSource也添加到类定义中。无论如何,谢谢!这也是要指出的此时,您将在崩溃日志/消息中找到一些信息,但您没有得到有趣的部分:“由于未捕获异常而终止应用程序'nsInternalInconsistencException',原因:'UITableView(;layer=;contentOffset:{0,-64};contentSize:{375,44}>)未能从其数据源()获取单元格();)