实例化领域对象时获取错误。检查下面提到的代码。
导入RealmSwift
class DB {
let db: Realm!
init() {
self.db = try! Realm()
}
}
在viewController中,我试图实例化一个数据库对象。
class ViewController: UIViewController {
var database: DB!
override func viewDidLoad() {
super.viewDidLoad()
self.database = DB.init()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
控制台中的错误消息是:
2016-10-24 07:56:10.852860 ExpenseIt[1009:8624] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-24 07:56:10.860310 ExpenseIt[1009:8624] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-24 07:56:10.869424 ExpenseIt[1009:8619] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-10-24 07:56:10.881984 ExpenseIt[1009:8580] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-24 07:56:10.932322 ExpenseIt[1009:8619] subsystem: com.apple.libsqlite3, category: logging, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-24 07:56:10.965507 ExpenseIt[1009:8619] subsystem: com.apple.network, category: , enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0
2016-10-24 07:56:10.965843 ExpenseIt[1009:8619] [] tcp_connection_create_with_endpoint_and_parameters 2 static.realm.io 443
2016-10-24 07:56:10.966149 ExpenseIt[1009:8633] [] tcp_connection_create_with_endpoint_and_parameters 1 api.mixpanel.com 443
2016-10-24 07:56:10.966 ExpenseIt[1009:8580] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSInvocation getArgument:atIndex:]: struct with unknown contents found while getting argument at index -1'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108c9334b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010621421e objc_exception_throw + 48
2 CoreFoundation 0x0000000108c18fe9 -[NSInvocation getArgument:atIndex:] + 473
3 Foundation 0x0000000105da76d6 _NSGetValueWithMethod + 174
4 Foundation 0x0000000105d1bf2b -[NSObject(NSKeyValueCoding) valueForKey:] + 283
5 Realm 0x0000000105748b13 -[RLMObjectBase valueForKey:] + 86
6 Realm 0x0000000105757fce -[RLMProperty initSwiftPropertyWithName:indexed:linkPropertyDescriptor:property:instance:] + 354
7 Realm 0x000000010574ba6a +[RLMObjectSchema propertiesForClass:isSwift:] + 730
8 Realm 0x000000010574a966 +[RLMObjectSchema schemaForObjectClass:] + 437
9 Realm 0x00000001057c367e _ZL16RLMRegisterClassP10objc_class + 145
10 Realm 0x00000001057c3eba __25+[RLMSchema sharedSchema]_block_invoke + 12
11 CoreFoundation 0x0000000108c1a9d6 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
12 CoreFoundation 0x0000000108c1a8af -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 159
13 Realm 0x00000001057c3d3b +[RLMSchema sharedSchema] + 142
14 Realm 0x00000001057bafec +[RLMRealm realmWithConfiguration:error:] + 1230
15 RealmSwift 0x0000000105634a24 _TFC10RealmSwift5RealmcfzT_S0_ + 100
16 ExpenseIt 0x000000010555d845 _TFC9ExpenseIt2DBcfT_S0_ + 37
17 ExpenseIt 0x000000010555d8bf _TFC9ExpenseIt2DBCfT_S0_ + 47
18 ExpenseIt 0x000000010555c8e8 _TFC9ExpenseIt14ViewController11viewDidLoadfT_T_ + 88
19 ExpenseIt 0x000000010555c972 _TToFC9ExpenseIt14ViewController11viewDidLoadfT_T_ + 34
20 UIKit 0x00000001074f506d -[UIViewController loadViewIfRequired] + 1258
21 UIKit 0x00000001074f54a0 -[UIViewController view] + 27
22 UIKit 0x00000001073bf045 -[UIWindow addRootViewControllerViewIfPossible] + 71
23 UIKit 0x00000001073bf796 -[UIWindow _setHidden:forced:] + 293
24 UIKit 0x00000001073d30a9 -[UIWindow makeKeyAndVisible] + 42
25 UIKit 0x000000010734c259 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
26 UIKit 0x00000001073523b9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
27 UIKit 0x000000010734f539 -[UIApplication workspaceDidEndTransaction:] + 188
28 FrontBoardServices 0x000000010bb5c76b __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
29 FrontBoardServices 0x000000010bb5c5e4 -[FBSSerialQueue _performNext] + 189
30 FrontBoardServices 0x000000010bb5c96d -[FBSSerialQueue _performNextFromRunLoopSource] + 45
31 CoreFoundation 0x0000000108c38311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
32 CoreFoundation 0x0000000108c1d59c __CFRunLoopDoSources0 + 556
33 CoreFoundation 0x0000000108c1ca86 __CFRunLoopRun + 918
34 CoreFoundation 0x0000000108c1c494 CFRunLoopRunSpecific + 420
35 UIKit 0x000000010734ddb6 -[UIApplication _run] + 434
36 UIKit 0x0000000107353f34 UIApplicationMain + 159
37 ExpenseIt 0x000000010555e5ff main + 111
38 libdyld.dylib 0x000000010716168d start + 1
39 ??? 0x0000000000000001 0x0 + 1
)
2016-10-24 07:56:10.966479 ExpenseIt[1009:8619] [] tcp_connection_start 2 starting
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
如果有人能帮助我,我将非常感激。
答案 0 :(得分:0)
对不起家伙浪费你宝贵的时间。 xcode在运行时因为在模型中使用不受支持的数据类型而引发错误。
似乎jpsim告诉我,我重新查看并发现我使用的是Realm不支持的数据类型。即使我没有实例化我的模型的对象,Realm仍然以某种方式检测它并将其标记为错误。虽然我希望错误更明确。
感谢各位帮助我找到答案的人。