Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40136

Swift PHAsset from NSURL

I am working on PHAsset and NSURL on Swift. I have an image url, for example file:///var/mobile/Media/DCIM/100APPLE/IMG_0043.JPG.

How can i make a PHAsset from this NSURL in Swift?

Upvotes: 4

Views: 7392

Answers (1)

Salman Ghumsani
Salman Ghumsani

Reputation: 3657

A PHAsset object represents an image or video file that appears in the Photos app, including iCloud Photos content. To display or edit assets, use the PHAsset class to fetch asset objects for the photos or videos you want to work with. An asset object is immutable and contains only the metadata for the photo or video it represents.

Thus you can not make PHAsset object. Here is only one constructor for making object.

let asset   =   PHAsset()

There is no constructor for NSURL :-

This is what we frequently use:-

let imgData = NSData(contentsOfURL: (NSURL(string: "file:///var/mobile/Media/DCIM/100APPLE/IMG_0043.JPG"))!)
let image = UIImage(data: imgData!)

Upvotes: 8

Related Questions