HomeiOS Developmentios - Displaying photographs that had been downloaded from Apple ODR

ios – Displaying photographs that had been downloaded from Apple ODR


I’ve a set of photographs that I’ve added to the “cat-images” tag below Useful resource Tags in Xcode. In testing, I’ve finished this:

let resourceRequest = NSBundleResourceRequest(tags: Set(["cat-images"]))
        resourceRequest.conditionallyBeginAccessingResources { (resourcesAvailable) in
            if resourcesAvailable {
                completion(nil)
            } else {
                resourceRequest.beginAccessingResources { (error) in
                    completion(error)
                }
            }
        }

This completes efficiently, however then after I attempt do show one of many photographs from that set:

UIImage(named: "siamese.png").map { Picture(uiImage: $0) }

The picture can’t be discovered. Do I have to entry the picture another way if it is a part of ODR? Does each single picture within the folder have to have its personal tag? Proper now they’re all tagged with “cat-images” however they do not have distinctive ODR tags.

I’ve additionally tried loading the picture like this:

extension Picture {
    static func loadFromODR(resourceName: String) -> Picture? {
        let parts = resourceName.break up(separator: ".")
        let title = String(parts[0])
        let ext = String(parts[1])
        print("trying odr picture: (title).(ext)")
        guard let path = Bundle.important.path(forResource: title, ofType: ext),
              let picture = UIImage(contentsOfFile: path) else {
            print("couldn't discover: (title).(ext)")
            return nil
        }
        return Picture(uiImage: picture)
    }
}

however the picture can’t be discovered.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments