Difference between revisions of "Swift Extensions"
Jump to navigation
Jump to search
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-...") |
(No difference)
|
Latest revision as of 21:56, 16 October 2021
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
}
}