Files
ihatepdfs/sources/core/PDFFileSelection.swift

20 lines
588 B
Swift
Raw Permalink Normal View History

2026-06-24 17:51:26 -07:00
import Foundation
import UniformTypeIdentifiers
public enum PDFFileSelection {
public static func isPDFFileURL(_ url: URL) -> Bool {
guard url.isFileURL else { return false }
let resourceValues = try? url.resourceValues(forKeys: [.contentTypeKey, .isDirectoryKey])
if resourceValues?.isDirectory == true {
return false
}
if let contentType = resourceValues?.contentType {
return contentType.conforms(to: .pdf)
}
return url.pathExtension.localizedCaseInsensitiveCompare("pdf") == .orderedSame
}
}