Swift Extensions
Revision as of 21:56, 16 October 2021 by PeterHarding (talk | contribs) (Created page with "These often provide a succinct way of cleanly extending existing classes. =PHAsset= From - http://stackoverflow.com/questions/27854937/ios8-photos-framework-how-to-get-the-...")
These often provide a succinct way of cleanly extending existing classes.
PHAsset
extension PHAsset { var originalFilename: String? { var fname: String? if #available(iOS 9.0, *) { let resources = PHAssetResource.assetResources(for: self) if let resource = resources.first { fname = resource.originalFilename } } if fname == nil { // This is an undocumented workaround that works as of iOS 9.1 fname = self.value(forKey: "filename") as? String } return fname } }