gpt4 book ai didi

swift3 - 如何在 Swift 3 中将图像从文档目录显示到 UIImageView?

转载 作者:行者123 更新时间:2023-12-04 14:56:13 24 4
gpt4 key购买 nike

下面的 Swift 2 示例给出了这个错误:

Value of type String has no member 'stringByAppendingPathComponent'



Screenshot of Error

我需要为 Swift 3 更改什么?

最佳答案

Apple 正试图将每个人从路径作为字符串范式转移到 URL(即 file:///path/to/file.text )。 Swift API 几乎删除了所有 path赞成 URL .

你仍然可以在 Objective-C ( NSString ) 中找到它:

let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let getImagePath = NSString.path(withComponents: [paths, "fileName"])

更快捷的方式:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = URL(fileURLWithPath: paths).appendingPathComponent("fileName")

关于swift3 - 如何在 Swift 3 中将图像从文档目录显示到 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028248/

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