我有一些使用try and catch的代码,但是我看到了一些与该代码有关的崩溃报告。怎么可能呢?我该如何捕捉所有这些崩溃?
代码(使用SwiftyJSON):
@objc class func produce(data: Data) -> [MyPair]? {
guard let json = try? JSON(data: data) else {
return nil
}
var pairs : [MyPair] = []
do {
let itemArray = try json["key1"]["key2"]["key3"].arrayValue()
for item in itemArray {
pairs.append(buildPair(with: item))
}
} catch {
print(error)
}
return pairs
}
其中一次崩溃的堆栈跟踪:
0 libswiftCore.dylib 0x00000001028d1fcc 0x102624000 + 2809804
1 libswiftCore.dylib 0x00000001028d2000 0x102624000 + 2809856
2 MyApp 0x00000001011d1290 generic specialization <Swift.String, Any> of Swift._VariantDictionaryBuffer.ensureUniqueNativeBuffer(withBucketCount: Swift.Int) -> (reallocated: Swift.Bool, capacityChanged: Swift.Bool) (SwiftyJSON.swift:0)
3 MyApp 0x00000001011d0d9c generic specialization <Swift.String, Any> of Swift._VariantDictionaryBuffer.nativeUpdateValue(_: B, forKey: A) -> B? (SwiftyJSON.swift:0)
4 MyApp 0x00000001011b9620 SwiftyJSON.(unwrap in _4625CC38AABF536BB76490A35D7233C9)(Any) -> Any (SwiftyJSON.swift:0)
5 MyApp 0x00000001011b9314 SwiftyJSON.(unwrap in _4625CC38AABF536BB76490A35D7233C9)(Any) -> Any (SwiftyJSON.swift:0)
6 MyApp 0x00000001011b95f8 SwiftyJSON.(unwrap in _4625CC38AABF536BB76490A35D7233C9)(Any) -> Any (SwiftyJSON.swift:276)
7 MyApp 0x00000001011b9314 SwiftyJSON.(unwrap in _4625CC38AABF536BB76490A35D7233C9)(Any) -> Any (SwiftyJSON.swift:0)
8 MyApp 0x00000001011b95f8 SwiftyJSON.(unwrap in _4625CC38AABF536BB76490A35D7233C9)(Any) -> Any (SwiftyJSON.swift:276)
9 MyApp 0x00000001011b8324 SwiftyJSON.JSON.object.setter : Any (SwiftyJSON.swift:231)
10 MyApp 0x00000001011d3c30 function signature specialization <Arg[1] = Dead> of SwiftyJSON.JSON.init(jsonObject: Any) -> SwiftyJSON.JSON (SwiftyJSON.swift:141)
11 MyApp 0x00000001011d3e2c function signature specialization <Arg[1] = Dead> of SwiftyJSON.JSON.init(Any) -> SwiftyJSON.JSON (<compiler-generated>:0)
12 MyApp 0x00000001011d4354 function signature specialization <Arg[0] = Exploded> of SwiftyJSON.JSON.subscript.getter : (key: Swift.String) -> SwiftyJSON.JSON (<compiler-generated>:0)
13 MyApp 0x00000001011c5540 SwiftyJSON.JSON.subscript.getter : ([SwiftyJSON.JSONSubscriptType]) -> SwiftyJSON.JSON (SwiftyJSON.swift:0)
14 MyApp 0x00000001011b8f90 SwiftyJSON.JSON.subscript.getter : (SwiftyJSON.JSONSubscriptType...) -> SwiftyJSON.JSON (SwiftyJSON.swift:506)
15 MyApp 0x0000000101057228 function signature specialization <Arg[1] = Dead> of static MyApp.PairFactory.produce(data: Foundation.Data) -> [MyApp.MyPair]? (PairFactory.swift:18)
16 MyApp 0x0000000101054968 @objc static MyApp.PairFactory.produce(data: Foundation.Data) -> [MyApp.MyPair]? (<compiler-generated>:0)
17 MyApp 0x0000000100e7d250 -[MyParseOperation unityFeedWithData] (MyParseOperation.m:206)
18 MyApp 0x0000000100e7c37c -[MyParseOperation start] (MyParseOperation.m:93)
19 Foundation 0x00000001837c476c __NSOQSchedule_f + 400
20 libdispatch.dylib 0x000000018268cae4 _dispatch_client_callout + 12
21 libdispatch.dylib 0x00000001826c97a8 _dispatch_continuation_pop$VARIANT$armv81 + 412
22 libdispatch.dylib 0x00000001826c8180 _dispatch_async_redirect_invoke$VARIANT$armv81 + 592
23 libdispatch.dylib 0x00000001826ce3a4 _dispatch_root_queue_drain + 588
24 libdispatch.dylib 0x00000001826ce0f0 _dispatch_worker_thread3 + 108
25 libsystem_pthread.dylib 0x00000001829bffac _pthread_wqthread + 1172
26 libsystem_pthread.dylib 0x00000001829bfb08 start_wqthread + 0