Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 322
Sazzad Hissain Khan Avatar asked Sep 08 '25 18:09

Sazzad Hissain Khan


1 Answers

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!)
like image 179
Salman Ghumsani Avatar answered Sep 10 '25 06:09

Salman Ghumsani