Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error with trying to save Image #18

Closed
feodormak opened this issue Oct 26, 2017 · 4 comments
Closed

Fatal error with trying to save Image #18

feodormak opened this issue Oct 26, 2017 · 4 comments

Comments

@feodormak
Copy link

I've tried to save an image as shown in your example, and the app always crashes with,

fatal error: Optional does not conform to Encodable because UIImage does not conform to Encodable

When I hold down Alt/Option and hover over my declaration, it shows the declaration for the Codable initializer even though I've used Disk.save with an UIImage.

Any ideas if I am using it wrong?

@saoudrizwan
Copy link
Owner

Hey @feodormak, can you please comment the code that you're trying to run?

@feodormak
Copy link
Author

The code i was trying to run is

@IBAction func saveToAppSupp(_ sender: UIButton) {
        let image = UIImage(named: "apple.png")
        do {
            try Disk.save(image, to: .applicationSupport, as: "apple.png")
        }
        catch { }
    }

At runtime, it gives this error,

fatal error: Optional<UIImage> does not conform to Encodable because UIImage does not conform to Encodable.: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.65.2/src/swift/stdlib/public/core/Codable.swift, line 3962
2017-10-27 14:44:56.078139+0800 boxApp[986:26400] fatal error: Optional<UIImage> does not conform to Encodable because UIImage does not conform to Encodable.: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.65.2/src/swift/stdlib/public/core/Codable.swift, line 3962

Not sure if it's related, by when I Alt-Control over the function, this is what I get,
untitled
and I am guessing that's why it's throwing the 'does not conform to Encodable' error.

@feodormak
Copy link
Author

Ok, apologies. Solved it. My noob mistake. The UIImage optional needs to be unwrapped to be used. Thanks!

@saoudrizwan
Copy link
Owner

Glad you figured it out :^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants