我正在尝试将RealmObjects写入数据库,当我尝试插入它时,我收到此属性incompatible type
错误。问题是它说它不能持久保存属性timestampe
,即使我的RealmObject中不存在这个属性。这是领域中的领域对象:
class TransferR: Object {
@objc dynamic var from_stop_id: String = ""
@objc dynamic var to_stop_id: String = ""
@objc dynamic var transfer_type: String = ""
@objc dynamic var min_transfer_time: String = ""
@objc dynamic var transfer_id:String = ""
required convenience init(from_stop_id: String = "", to_stop_id: String = "", transfer_type: String = "", min_transfer_time: String = "") {
self.init()
self.from_stop_id = from_stop_id
self.to_stop_id = to_stop_id
self.transfer_type = transfer_type
self.min_transfer_time = min_transfer_time
self.transfer_id = transfer_type + "_" + from_stop_id + "_" + to_stop_id
}
override static func primaryKey() -> String? {
return "transfer_id"
}
override static func indexedProperties() -> [String] {
return ["from_stop_id", "to_stop_id"]
}
}
正如您所看到的,没有任何外来类型,也没有timestamp
属性。有什么想法吗?
编辑---------------- 这是打印完整的错误:
2018-04-26 12:04:55.243453-0400 WheresMyTrain[37970:1417331] Parsing transfers.txt file.
2018-04-26 12:04:55.565504-0400 WheresMyTrain[37970:1417092] *** Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'timestamp' with incompatible type. Add to Object.ignoredProperties() class method to ignore.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010334712b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001029dbf41 objc_exception_throw + 48
2 Realm 0x00000001016ef7eb -[RLMProperty initSwiftPropertyWithName:indexed:linkPropertyDescriptor:property:instance:] + 2523
3 Realm 0x00000001016cdeac +[RLMObjectSchema propertiesForClass:isSwift:] + 1996
4 Realm 0x00000001016cbd5d +[RLMObjectSchema schemaForObjectClass:] + 941
5 Realm 0x000000010183f20b _ZL16RLMRegisterClassP10objc_class + 299
6 Realm 0x000000010184056d __25+[RLMSchema sharedSchema]_block_invoke + 77
7 CoreFoundation 0x00000001032cbd72 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 226
8 Realm 0x0000000101840224 +[RLMSchema sharedSchema] + 1044
9 Realm 0x000000010181b04b +[RLMRealm realmWithConfiguration:error:] + 5627
10 RealmSwift 0x00000001022293a2 _T0So8RLMRealmCABSo0A13ConfigurationC13configuration_tKcfCTO + 162
11 RealmSwift 0x000000010222921e _T010RealmSwift0A0CACyKcfc + 126
12 RealmSwift 0x0000000102229146 _T010RealmSwift0A0CACyKcfC + 54
13 WheresMyTrain 0x0000000100775435 _T013WheresMyTrain10GtfsParserC5realm10RealmSwift0G0Cfg + 325
14 WheresMyTrain 0x000000010077de78 _T013WheresMyTrain10GtfsParserC10parseTable33_4859CB298B2937F388A70DD051310579LLySS5table_10Foundation3URLV4fileAA12RowProcessorC2rptF + 2232
15 WheresMyTrain 0x000000010077ce54 _T013WheresMyTrain10GtfsParserC14createRealmObj33_4859CB298B2937F388A70DD051310579LLy10Foundation3URLV4file_SS5tabletF + 15300
16 WheresMyTrain 0x0000000100778488 _T013WheresMyTrain10GtfsParserC05parseD033_4859CB298B2937F388A70DD051310579LLy10Foundation3URLV3url_tF + 4936
17 WheresMyTrain 0x0000000100776e68 _T013WheresMyTrain10GtfsParserC022downloadAndParseLatestD0yyFy9Alamofire16DownloadResponseVy10Foundation4DataVGcfU_ + 440
18 WheresMyTrain 0x000000010077713c _T013WheresMyTrain10GtfsParserC022downloadAndParseLatestD0yyFy9Alamofire16DownloadResponseVy10Foundation4DataVGcfU_TA + 12
19 Alamofire 0x0000000100cb1696 _T09Alamofire16DownloadResponseVy10Foundation4DataVGIxx_AGIxi_TR + 246
20 Alamofire 0x0000000100cb1732 _T09Alamofire16DownloadResponseVy10Foundation4DataVGIxx_AGIxi_TRTA + 66
21 Alamofire 0x0000000100cb043d _T09Alamofire15DownloadRequestC8responseACXDSo13DispatchQueueCSg5queue_x0D10SerializeryAA0B8ResponseVy16SerializedObjectQzGc17completionHandlertAA0biH8ProtocolRzlFyycfU_yycfU_ + 1181
22 Alamofire 0x0000000100cb673e _T09Alamofire15DownloadRequestC8responseACXDSo13DispatchQueueCSg5queue_x0D10SerializeryAA0B8ResponseVy16SerializedObjectQzGc17completionHandlertAA0biH8ProtocolRzlFyycfU_yycfU_TA + 110
23 Alamofire 0x0000000100c642e9 _T0Ix_IyB_TR + 41
24 libdispatch.dylib 0x00000001084572f7 _dispatch_call_block_and_release + 12
25 libdispatch.dylib 0x000000010845833d _dispatch_client_callout + 8
26 libdispatch.dylib 0x00000001084635f9 _dispatch_main_queue_callback_4CF + 628
27 CoreFoundation 0x0000000103309e39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
28 CoreFoundation 0x00000001032ce462 __CFRunLoopRun + 2402
29 CoreFoundation 0x00000001032cd889 CFRunLoopRunSpecific + 409
30 GraphicsServices 0x000000010bb909c6 GSEventRunModal + 62
31 UIKit 0x00000001044115d6 UIApplicationMain + 159
32 WheresMyTrain 0x000000010064f5b7 main + 55
33 libdyld.dylib 0x00000001084d4d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
2018-04-26 12:05:35.025148-0400 WheresMyTrain[37970:1419045] Version 3.5.0 of Realm is now available: https://github.com/realm/realm-cocoa/blob/v3.5.0/CHANGELOG.md
我的整个项目中没有timestamp
属性,所以我不确定它来自哪里。这是插入领域db的代码:
while csv.next() != nil {
let row = rp.process(csv: csv)
realmObjects.append(row)
if (realmObjects.count > 10000) {
try realm.write {
realm.add(row)
}
DDLogInfo("Committing /(realmObjects.count) to the \(table) table.")
realmObjects = Array<Object>()
}
}
我没有对db做任何异国情调。