A simple Swift utility for managing and retrieving app icon details in iOS.
The AppIcon
struct provides static properties and functions that facilitate seamless interaction with your application's icon settings. With capabilities to check for alternate icon support, determine the current icon, fetch all defined icons, and set an alternate icon.
You can add AppIcon
as a dependency to your project using Swift Package Manager by adding it to the dependencies value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/kevinhermawan/AppIcon.git", .upToNextMajor(from: "2.0.0"))
]
Alternatively, in Xcode:
- Open your project in Xcode.
- Click on
File
->Swift Packages
->Add Package Dependency...
- Enter the repository URL:
https://github.com/kevinhermawan/AppIcon.git
- Choose the version you want to add. You probably want to add the latest version.
- Click
Add Package
.
import AppIcon
// Checking if alternate icons are supported
if AppIcon.isSupported {
print("Alternate icons are supported!")
} else {
print("Alternate icons are not supported.")
}
// Fetching the current app icon details
if let currentIcon = AppIcon.current {
print("Current app icon: \(currentIcon.label) - \(currentIcon.iconName)")
} else {
print("Using default app icon")
}
// Fetching all defined icons
for icon in AppIcon.defined {
print("\(icon.label) - \(icon.iconName)")
}
// Retrieving a specific icon by its iconName
let iconName = "Alternate1"
if let specificIcon = AppIcon.icon(for: iconName) {
print("Found icon: \(specificIcon.label) - \(specificIcon.iconName)")
} else {
print("Icon not found for name \(iconName)")
}
// Setting an alternate app icon (for example, "Alternate1")
if let iconToSet = AppIcon.defined.first(where: { $0.iconName == "Alternate1" }) {
AppIcon.set(to: iconToSet) { error in
if let error = error {
print("Failed to set app icon: \(error.localizedDescription)")
} else {
print("App icon successfully set!")
}
}
} else {
print("Failed to find the specified icon.")
}