Xcode调试:在变量列表中可以看到imageURL时,在作用域中找不到“imageURL”

luaexgnf  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(109)


的数据
我已经挠了一个小时的头了,还是想不出为什么会这样。
在if语句中定义的字符串变量(holdCountString、copyCountString、isbn、upc)也存在同样的问题
我已经尝试过清理build文件夹,清理Xcode缓存,重启计算机,然后重新打开Xcode,然而,调试器仍然说“无法在范围内找到'imageURL'”。

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处理它以提取每个搜索结果的所有容器元素,然后使用newSearchResult(from:)处理每个容器元素。这两个函数都是异步的。
search视图使用以下代码调用searchResults(for:):

.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)
        }
    }
}

2w3rbyxf

2w3rbyxf1#

Swift论坛线程"Swift Concurrency / LLDB unable to print object"提供了并发和Xcode调试器LLDB之间存在已知问题的信息,该问题导致cannot find '…' in scope错误:
然而,在很多情况下,当我处于Task或并发执行的上下文中时,LLDB拒绝为我工作
我们可以证实这点。对于所有的异步函数(在Task中),我们总是收到这个错误消息。不幸的是,我还没有找到解决这种行为的方法。根本原因是self is unavailable
在解决此问题之前,解决方法可能如下所示:

log(level: .debug, msg: "varName is \(varName)")

// --- or ---

#if DEBUG
print(varName)
#endif

字符串

相关问题