Swift extensions for retrieving file icons and path metadata on macOS. Get effective, custom, or resolved icons for any file URL, plus convenient String helpers for extracting file names and extensions.
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/StefKors/FileIconKit.git", from: "1.0.0")
]import FileIconKit
let url = URL(fileURLWithPath: "/Applications/Safari.app")
// Get the resolved icon (custom icon if set, otherwise effective icon)
if let icon = url.resolvedIcon {
// Use the NSImage
}
// String path helpers
let name = "/path/to/file.pdf".fileName() // "file"
let ext = "/path/to/file.pdf".fileExtension() // "pdf"| Property | Type | Description |
|---|---|---|
effectiveIcon |
NSImage? |
System-determined icon for the file |
customIcon |
NSImage? |
Custom icon set on the file, if any |
resolvedIcon |
NSImage? |
Custom icon, falling back to effective icon |
contentAccessDate |
Date? |
Last access date of the file |
| Method | Returns | Description |
|---|---|---|
fileName() |
String |
File name without extension |
fileExtension() |
String |
File extension |
MIT