快速写入数据时,领域崩溃

时间:2018-08-01 18:18:42

标签: crash realm swift4 today-extension

我的ios应用程序有一个今天的扩展程序,该扩展程序通过rest调用从Internet获取数据,然后将rest调用的响应保存到realm db,并在扩展控制器中更新db的内容。

偶尔我发现使用以下堆栈跟踪更新db内容崩溃的代码

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called

Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                	0x1843a2d8c __exceptionPreprocess + 228
1   libobjc.A.dylib               	0x18355c5ec objc_exception_throw + 55
2   Realm                         	0x100f53c84 invocation function for block in objc_object* (anonymous namespace)::makeBoxedGetter<realm::StringData>(unsigned long) + 359556 (RLMObject_Private.hpp:45)
3   Darb Live Widget              	0x100a3007c closure #1 in closure #1 in TodayViewController.updateData() + 114812 (TodayViewController.swift:164)
4   RealmSwift                    	0x100bce3a0 Realm.write(_:) + 140192 (Realm.swift:155)
5   Darb Live Widget              	0x100a2fee4 closure #1 in TodayViewController.updateData() + 114404 (TodayViewController.swift:163)
6   Darb Live Widget              	0x100a3ee2c specialized DetailDepartureBoardOperation.onRequestSuccess(_:operation:response:) + 175660 (DetailDepartureBoardOperation.swift:58)
7   Darb Live Widget              	0x100a3e298 protocol witness for CallerDelegate.onRequestSuccess(_:operation:response:) in conformance DetailDepartureBoardOperation + 172696 (DetailDepartureBoardOperation.swift:55)
8   Darb Live Widget              	0x100a4e8a8 specialized closure #1 in BaseCaller.execute(_:contentType:) + 239784 (BaseCaller.swift:136)
9   Darb Live Widget              	0x100a4e518 closure #1 in BaseCaller.execute(_:contentType:) + 238872 (BaseCaller.swift:0)
10  Darb Live Widget              	0x100a3115c _T0So22AFHTTPRequestOperationCypIegxi_AByXlIeyByy_TR + 119132 (TodayViewController.swift:0)
11  libdispatch.dylib             	0x183c94b24 _dispatch_call_block_and_release + 23
12  libdispatch.dylib             	0x183c94ae4 _dispatch_client_callout + 15
13  libdispatch.dylib             	0x183ca1520 _dispatch_main_queue_callback_4CF$VARIANT$mp + 563
14  CoreFoundation                	0x18434b070 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
15  CoreFoundation                	0x184348bc8 __CFRunLoopRun + 2271
16  CoreFoundation                	0x184268da8 CFRunLoopRunSpecific + 551
17  GraphicsServices              	0x18624b020 GSEventRunModal + 99
18  UIKit                         	0x18e24978c UIApplicationMain + 235
19  libxpc.dylib                  	0x184011b7c _xpc_objc_main + 555
20  libxpc.dylib                  	0x184013c28 xpc_main + 179
21  Foundation                    	0x184f0dfd4 -[NSXPCListener resume] + 179
22  PlugInKit                     	0x189a08ec4 -[PKService run] + 711
23  PlugInKit                     	0x189a08ab4 +[PKService main] + 55
24  PlugInKit                     	0x189a08ee8 +[PKService _defaultRun:arguments:] + 19
25  Foundation                    	0x184ef4a98 NSExtensionMain + 63
26  libdyld.dylib                 	0x183cf9fc0 start + 3

下面给出的是它指向的代码:

public func updateData() {
    for item in subArray {
        // Get the ID's of the stop and update their data
        let departureBoardperation = DetailDepartureBoardOperation(text:item.stopId!)
        departureBoardperation.getResponse({ (response) in

            try? self.realm!.write ({
                let busItem = self.realm.objects(UserPreferedStop.self).filter("stopId = %@", item.stopId!)
                let data = self.parseData(data: response,stopId: item.stopId!,targetObj: busItem.first!)
                self.realm?.add(data,update: true)

                self.tableView.reloadData()
            })

        }, failure: { (error) in
            // update failed :(
            print(error)
        })

    }
    self.tableView.reloadData()
}

有人可以帮助我解决此问题吗?

0 个答案:

没有答案