Aprilday
Landmark.swift 这个文件中 ‘ ImageStore’ 报 ‘Use of unresolved identifier 'ImageStore'’
#5 · closed · 1 comments
Landmark.swift 这个文件中 ‘ ImageStore’ 报 ‘Use of unresolved identifier 'ImageStore'’
1. 查看 `../SwiftUI-Tutorials-master/SwiftUI-Essentials/Models/Data.swift` 文件是否存在并且引入到了工程中。 2. 查看 `Data.swift` 文件中 `ImageStore` 相关的代码是否正常,即: ```swift final class ImageStore { typealias _ImageDictionary = [String: CGImage] fileprivate var images: _ImageDictionary = [:] fileprivate static var scale = 2 static var shared = ImageStore() func image(name: String) -> Image { let index = _guaranteeImage(name: name) return Image(images.values[index], scale: CGFloat(ImageStore.scale), label: Text(verbatim: name)) } static func loadImage(name: String) -> CGImage { guard let url = Bundle.main.url(forResource: name, withExtension: "jpg"), let imageSource = CGImageSourceCreateWithURL(url as NSURL, nil), let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else { fatalError("Couldn't load image \(name).jpg from main bundle.") } return image } fileprivate func _guaranteeImage(name: String) -> _ImageDictionary.Index { if let index = images.index(forKey: name) { return index } images[name] = ImageStore.loadImage(name: name) return images.index(forKey: name)! } } ```