Search code examples
iosimageswift3pathbundle

Cannot extract image path from project bundle


I am trying to get the path to an icon image which is part of the Xcode project, but without luck. I can create an image using the name, but i need the path.

let img = Bundle.main.path(forResource: "credit.jpg", ofType:"jpg")

let imm = UIImage(named: "credit.jpg")

I can see that img is nil but imm is not.
Any ideas?


Solution

  • Please Check this:

    For Image Path:

    let img = Bundle.main.path(forResource: "credit", ofType: "jpg")
    print(img!)
    

    For Image Url:

    let img = Bundle.main.url(forResource: "credit", withExtension: "jpg")
    print(img!)