But robnotyou, I'm looking for a BIG win! 😁 Thanks so much for the quick response! It might upset my already-tuned settings, but I'll try it out.
Post
Replies
Boosts
Views
Activity
In the example below for Swift users, "UTType.mpeg4Movie" replaces "kUTTypeMPEG4"
The dev group did a nice job cleaning up the syntax. The dev docs group dropped the ball by noting that that "typeIdentifierKey" is deprecated, but not mentioning that "contentTypeKey" is the intended replacement - https://developer.apple.com/documentation/foundation/urlresourcekey/1416354-typeidentifierkey. The "contentTypeKey" could refer to anything; "contentTypeIdentifierKey" or "contentUTIdentiferKey" would have made it several hours easier to figure out.
Note: the example extension of URL maybe applies solely to macOS and/or file URLs. Advance apologies for typos.
Sample usage for casual hobbyists like me:
let myFileURL = URL( ... appropriate initialization here ...)
// unwrap as needed
if myFileURL.isMPEG4{
//do stuff
}
Extension:
extension URL {
// new style
var contentType: UTType? {
return (try? resourceValues(forKeys: [.contentTypeKey]))?.contentType
}
var isMPEG4:Bool {
guard let contentType = contentType else {return false} // search for contentType failed
return contentType.conforms(to: UTType.mpeg4Movie) ? true : false
}
// this is deprecated (macOS > 12?)
// based on: https://stackoverflow.com/questions/28570627/how-to-find-file-uti-for-file-withouth-pathextension-in-a-path-in-swift
var typeIdentifier: String? {
return (try? resourceValues(forKeys: [.typeIdentifierKey]))?.typeIdentifier
// will need to convert output to CFString to test against UTTypeConformsTo
}
var DeprecatedIsMPEG4:Bool {
guard let typeIdentifier = typeIdentifier else {return false}
// test against the specific type
if UTTypeConformsTo(typeIdentifier as CFString, kUTTypeMPEG4) {return true}
return false
}
}