以下代码用于使用OperationQueues添加依赖项:
let operationQueue = OperationQueue.main
let operation1 = BlockOperation(block: {
self.makeAPICall()
})
let operation2 = BlockOperation(block: {
self.fetchImage(imageURL: modelObject.imageURL)
})
operationQueue.addOperation(operation1)
operationQueue.addOperation(operation2)
operation2.addDependency(operation1)
我在operation2块中遇到了线程错误。我错过了什么。能否请你帮忙。谢谢。
项目是通过优化编译的 - 步进可能表现得很奇怪;变量可能无法使用。 (lldb)bt * thread#1,queue =' com.apple.main-thread',stop reason = EXC_BAD_INSTRUCTION(code = EXC_I386_INVOP,subcode = 0x0) * frame#0:0x0000000104df1198项目
ViewController.(viewDidLoad() -> ()).(closure #2) [inlined] function signature specialization <Arg[0] = Owned To Guaranteed> of Project.ViewController.(viewDidLoad () -> ()).(closure #2) at ViewController.swift:61 [opt] frame #1: 0x0000000104df1198 Project
ViewController。(viewDidLoad() - &gt;())。(闭包#2)在ViewController.swift:60 [opt] 帧#2:0x0000000000000008 第3帧:0x00000001064b53b7基础` NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 7