CristianMoisei
CristianMoisei

Reputation: 2279

UIImage(named: ) works but Bundle.main.url(forResource: , withExtension) doesn't work

I am trying to get the url of an image in my assets folder to use it as the preview for a UIActivityViewController as suggested here. However I am getting nil for the path, even though the UIImage is working. I have checked if the extension is lowercase as suggested in another question and it is indeed. I have also tried using .path

Bundle.main.url(forResource: "emoji-2", withExtension: "jpg") // this is nil
UIImage(named: "emoji-2") // this is not nil

Any ideas what I'm doing wrong?

To confirm, the asset exists in my Assets library enter image description here

Upvotes: 0

Views: 583

Answers (1)

Leo Dabus
Leo Dabus

Reputation: 236360

Adding an image to the asset is not the same as adding it to the bundle. If you need an URL you can add it to your project or get the representation data from your image located in your asset, save it to a temporary location and share its URL.

Upvotes: 2

Related Questions