Xcode调试异常:变量列表可见imageURL却提示不在作用域
Xcode调试异常:
po命令提示变量不在作用域,但变量列表可见 调试过程中执行po imageURL命令时,Xcode调试器报错:cannot find 'imageURL' in scope,但imageURL明确显示在变量列表中(截图显示变量列表里存在该变量,但po命令执行失败)。
同样的问题也出现在if语句块内定义的holdCountString、copyCountString、isbn、upc等变量上。
已尝试的排查操作:
- 清理构建文件夹
- 清除Xcode缓存
- 重启电脑及Xcode
但以上操作均未解决问题,调试器仍提示变量不在作用域。
相关代码
核心处理函数
static func newSearchResult(from record: SwiftSoup.Element) async throws -> SearchResult? { let title = try record.select(CSSSelector.title.rawValue).text() let author = try record.select(CSSSelector.author.rawValue).text() let typeString = try record.select(CSSSelector.type.rawValue).text() let type = ItemType(rawValue: typeString) if type == nil { return nil } var releaseYear = try record.select(CSSSelector.releaseYear.rawValue).text() if releaseYear.last == "." { releaseYear.removeLast() } let description = try record.select(CSSSelector.description.rawValue).text() let itemRelativePath = try record.select(CSSSelector.itemRelativePath.rawValue).attr(AttributeKey.href.rawValue) var holdCount = 0 var copyCount = 0 var imageURL: URL? = nil let sizeCode = try record.select(CSSSelector.mainImage.rawValue).attr(AttributeKey.imageSizeCode.rawValue) if type == .ebook { let overdriveID = try record.select(CSSSelector.overdriveImage.rawValue).attr(AttributeKey.overdriveID.rawValue) let availability = try await overdriveAvailability(forID: overdriveID) holdCount = availability.holdCount copyCount = availability.copyCount let overdriveImage = try await overdriveCoverImage(forID: overdriveID) imageURL = URL(string: overdriveImage.src) } else if type != .elearning && type != .evideo { let holdCountString = try record.select(CSSSelector.holdCount.rawValue).text() if holdCountString != "" { holdCount = Int(holdCountString.split(separator: " ")[0])! } let copyCountString = try record.select(CSSSelector.copyCount.rawValue).text() if copyCountString != "" { copyCount = Int(copyCountString.split(separator: " ")[0])! } let isbn = try record.select(CSSSelector.mainImage.rawValue).attr(AttributeKey.isbn.rawValue) let upc = try record.select(CSSSelector.mainImage.rawValue).attr(AttributeKey.upc.rawValue) imageURL = TPLAPI.syndeticsImageURL(usingISBN: isbn, orUPC: upc, withSizeCode: sizeCode) } return SearchResult( imageURL: imageURL, title: title, author: author, type: type!, releaseYear: releaseYear, description: description, copyCount: copyCount, holdCount: holdCount, itemRelativePath: itemRelativePath ) }
newSearchResult(from:)是异步函数,被异步函数searchResults(for:)调用,后者负责下载HTML文件,通过SwiftSoup提取搜索结果容器元素后,调用该函数处理每个元素。
视图调用代码
.onSubmit { Task { do { showProgressView.toggle() print("task started running for input: \(input)") searchResults = try await TPLAPI.searchResults(for: input) showProgressView.toggle() } catch { print(error.localizedDescription) } } }
内容的提问来源于stack exchange,提问作者mediter
相关产品推荐
相关产品推荐

