2016-10-23 3 views
0

Ошибка при создании объекта царства. Проверьте приведенный ниже код.NSInvalidArgumentException при создании экземпляра области

импорт 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

Показать все сообщения 'NSException'. Там должно быть больше об этом. – Larme

+0

Спасибо Larme за ответ. Я добавил полный вывод консоли. Дайте мне знать, если требуется другое. –

+0

Не могли бы вы поделиться своей полной схемой (классы модели Realm), поскольку, похоже, там есть что-то, что Realm не разбирается правильно. – jpsim

ответ

0

Извините, ребята, что потратили драгоценное время. xcode сбросил ошибку во время выполнения из-за использования неподдерживаемого типа данных в модели.

Кажется, что jpsim сказал, я снова просмотрел и обнаружил, что я использую тип данных, который не поддерживается Realm. И хотя я не создавал экземпляр объекта своей модели, Realm все еще каким-то образом обнаруживает его и помещает его как ошибку. Хотя я надеялся, что ошибка была более ясной.

Спасибо вам всем за помощь в оказании мне помощи.

Смежные вопросы