gpt4 book ai didi

ios - 在 Siesta 中覆盖本地数据?

转载 作者:行者123 更新时间:2023-11-28 14:08:23 26 4
gpt4 key购买 nike

我无法在 Swift 中为 Siesta 成功设置本地数据。我的目标是在本地为 URL 设置一个 UIImage,这样就可以在没有下载时间的情况下显示这个本地镜像。

为此,我将 URL 的图像数据设置为:

let resource = CustomRemoteImageView.imageCache.resource(myPhoto.url.absoluteString)
let imageData = UIImagePNGRepresentation(image)! // I've also tried putting the UIImage directly in there, because the transformation chain doesn't apply to local data, right?
let entity: Entity<Any> = Entity(content: imageData, contentType: "*/*") // I've played around with the content type too!
resource.overrideLocalData(with: entity)

然后我使用一个自定义服务,它总是尝试将内容解析为图像:

private let imageTransformer =
ResponseContentTransformer
{ Image(data: $0.content)}

convenience init() {
self.init(standardTransformers: [])
configure {
$0.pipeline[PipelineStageKey.parsing].add(self.imageTransformer, contentTypes: ["*/*"])
}
}

这个系统对所有远程图像都很好用,但它似乎总是无法解析这个被覆盖的本地镜像。它似乎正在尝试解析,但每次都失败。

即我得到一个 Siesta.ResourceEvent

(Siesta.ResourceEvent) $R20 = newData {
newData = network
}

但实际的 .typedContentnil

最佳答案

overrideLocalDataoverrideLocalContent 根本不与管道交互。 Siesta 不会尝试解析您传递的内容;你重写的就是你的资源得到的。

此外,overrideLocalDataoverrideLocalContent 不会失败。他们总是更新资源的内容。如果您调用这些方法,资源内容将与您传递的内容相匹配。

所以……问题不在于解析。可能是什么?

Entity.typedContent 是将 as? 应用于资源实体的 content 的快捷方式。如果您得到 nil,则意味着 (1) 您传递给 overrideLocalData 的实体的 content 为 nil 或 (2) 您在其中的上下文类型正在调用 typedContentcontent 的实际运行时类型不匹配。

如果打印 resource.latestData.content,您会看到什么?这将向您展示实际存在的内容,并将排除 typedContent 的类型转换问题。

如果它不是 nil,则比较其来自网络请求的值并获取匹配的类型。

如果它是 nil,那么要么其他东西清除了内容,要么你首先传递了 nil 内容。试试 SiestaLog.Category.enabled = .common 看看你是否能发现它在哪里或没有设置正确的东西。

关于ios - 在 Siesta 中覆盖本地数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52797382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com