所以我有2个ViewControllers
流程是MapStoreViewController - > StoreListViewController
在MapStoreViewController中,我调用API并将API保存到领域
Alamofire.request(urlRequest, encoding: URLEncoding.default, headers: headers).responseArray { (response: DataResponse<[OutletDTO]>) in
/* Check for server response */
var serverResponse = RestHelper.validateRequestResponse(response: response)
if serverResponse.0 == true {
if let responseObject = serverResponse.2 {
/* Open realm */
let realm = try! Realm()
let realmOutlet = realm.objects(OutletDTO.self)
/* Delete all the object stored in realm if there is any */
try! realm.write {
realm.delete(realmOutlet)
}
/* Loop the array from the response object and add it to realm */
if responseObject.count > 0 {
for eachOutlet in responseObject {
try! realm.write {
realm.add(eachOutlet)
}
}
}
serverResponse.2 = responseObject
completion(serverResponse.0, serverResponse.1, serverResponse.2)
}
}
然后MapStoreViewController上有一个条形按钮项,它将用户重定向到StoreListViewController
如果用户直接移动到StoreListViewController,几秒钟后,应用程序将因为此Object无效错误而崩溃
在StoreListViewController中,我也调用了上面的API。
试图研究我的流量。我发现如果我不在我的MapStoreViewController上调用API函数,应用程序就不会在StoreListViewController中崩溃。
如果两个VC都试图调用同样的API函数来访问该域,则会发生崩溃。
是否因为线程?我在这里缺少什么?
由于