Skip to content

Commit

Permalink
Minor pokes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddTheSane committed Oct 15, 2023
1 parent d53b8dc commit d7d711b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Other Sources/ADBToolkit/URL+ADBFilesystemHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ extension URL {
/// Analogous to `-[NSWorkspace preferredExtensionForFileType:]`.
static func preferredExtension(forFileType UTI: String) -> String? {
if #available(OSX 11.0, *) {
if let theUTI = UTType(UTI), let ext = theUTI.preferredFilenameExtension {
if let theUTI = UTType(UTI),
let ext = theUTI.preferredFilenameExtension {
return ext
}
}
Expand All @@ -183,7 +184,7 @@ extension URL {

let UTIForExtension = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
ext as NSString,
nil)?.takeRetainedValue()
nil)?.takeRetainedValue()
guard let theUTI = UTIForExtension as String? else {
return nil
}
Expand All @@ -204,7 +205,8 @@ extension URL {

/// Returns the UTI of the file at this URL, or `nil` if this could not be determined.
var typeIdentifier: String? {
guard let res = try? resourceValues(forKeys: [.typeIdentifierKey]), let theType = res.typeIdentifier else {
guard let res = try? resourceValues(forKeys: [.typeIdentifierKey]),
let theType = res.typeIdentifier else {
let pe = pathExtension
// Attempt to return a UTI based solely on our file extension instead.
if pe.count > 0 {
Expand All @@ -227,7 +229,7 @@ extension URL {
}
}
let reportedUTI = typeIdentifier
if let reportedUTI = reportedUTI, UTTypeConformsTo(reportedUTI as CFString, comparisonUTI as CFString) {
if let reportedUTI, UTTypeConformsTo(reportedUTI as CFString, comparisonUTI as CFString) {
return true
}

Expand All @@ -239,7 +241,9 @@ extension URL {
let ext = pathExtension
if ext.count != 0 {
let utiForExt = URL.fileType(forExtension: ext)
if let utiForExt = utiForExt, utiForExt != reportedUTI, UTTypeConformsTo(utiForExt as CFString, comparisonUTI as CFString) {
if let utiForExt,
utiForExt != reportedUTI,
UTTypeConformsTo(utiForExt as CFString, comparisonUTI as CFString) {
return true
}
}
Expand All @@ -251,7 +255,7 @@ extension URL {
/// URL conforms, or `nil` if it doesn't match any of them.
func matchingFileTypes(_ UTIs: Set<String>) -> String? {
let reportedUTI = typeIdentifier
if let reportedUTI = reportedUTI {
if let reportedUTI {
for comparisonUTI in UTIs {
if UTTypeConformsTo(reportedUTI as NSString, comparisonUTI as NSString) {
return comparisonUTI
Expand Down

0 comments on commit d7d711b

Please sign in to comment.