C. E.
C. E.

Reputation: 10627

Correct way to initialize URL() with a named asset in Swift?

I want to use the Vision framework with some images in my assets folder, but I'm struggling with initializing the URL that I need for the request handler:

let imageUrl = URL(what to put here?)
let handler = VNImageRequestHandler(url: imageUrl)

I can easily instantiate UIImage using UIImage(named: imageName) but there is no URL(named: imageName) and I can't figure out what I should use instead.

Upvotes: 1

Views: 351

Answers (1)

Sweeper
Sweeper

Reputation: 273600

VNImageRequestHandler also has an initialiser that accepts a CGImage, use that instead.

VNImageRequestHandler(cgImage: UIImage(named: "...").cgImage!)

Outside the context of VNImageRequestHandler, getting the URL from an image in the assets does not seem possible.

Upvotes: 2

Related Questions