自己解决できました。Arigato!
导入UIKit
ViewController 类:UIViewController {
@IBOutlet weak var imageView: UIImageView!
var documentsUrl: URL {
return Bundle.main.bundleURL
}
override func viewDidLoad() {
super.viewDidLoad()
print(documentsUrl)
imageView.image = load(fileName: "1.jpg")
}
private func load(fileName: String) -> UIImage? {
let fileURL = documentsUrl.appendingPathComponent(fileName)
do {
let imageData = try Data(contentsOf: fileURL)
return UIImage(data: imageData)
} catch {
print("Error loading image : \(error)")
}
return nil
}
}