我使用的是AlamoFire 5.0.2,并且偶尔会出现此错误。
NSInvalidArgumentException: -[__NSTaggedDate member:]: unrecognized selector sent to instance 0x8000000000000000
Thread 14
0 CoreFoundation ___exceptionPreprocess
1 libobjc.A.dylib _objc_exception_throw
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:]
3 CoreFoundation ____forwarding___
4 CoreFoundation ___forwarding_prep_0___
5 libswiftCore.dylib Swift.Set.insert(__owned A) -> (inserted: Swift.Bool, memberAfterInsert: A)
6 Example App closure #1 () -> () in AlamoFireSession.perform(DataRequest) -> () (AlamoFireSession.swift:826:33)
7 <compiler-generated> reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_unowned @convention(block) () -> ()
8 libdispatch.dylib __dispatch_call_block_and_release
9 libdispatch.dylib __dispatch_client_callout
10 libdispatch.dylib __dispatch_lane_serial_drain
11 libdispatch.dylib __dispatch_lane_invoke
12 libdispatch.dylib __dispatch_workloop_worker_thread
13 libsystem_pthread.dylib __pthread_wqthread
14 libsystem_pthread.dylib _start_wqthread
从AlamoFireSession.swift
,这个看起来就是崩溃的原因:
self.activeRequests.insert(request)
我有多个NSManagedObjectContext
,并且从它们内部和主线程调用AlamoFireSession.perform(DataRequest)
。
这意味着AlamoFireSession.perform(DataRequest)
是从多个线程调用的。这会导致车祸吗?
比如,如果我现在在哪里做这件事:
AlamoFireSession.default.request(...)
我将其替换为:
let queue = DispatchQueue(label:"all-requests-here")
// and then elsewhere
queue.async {
AlamoFireSession.default.request(...)
}
其中CCD_ 5对象被限定范围以便逗留在周围。
我环顾四周,发现最相似的是这个堆栈溢出问题,但不幸的是,这个问题没有得到回答。
如果是activeRequests
,则在5.2.0中修复了该问题。