Skip to content

Instantly share code, notes, and snippets.

@forcequitOS
Last active April 11, 2025 00:48
Show Gist options
  • Save forcequitOS/a2c0b14bf679ae37a9d134985eed36e2 to your computer and use it in GitHub Desktop.
Save forcequitOS/a2c0b14bf679ae37a9d134985eed36e2 to your computer and use it in GitHub Desktop.
Private/Internal SF Symbols for all Apple platforms
// Credits: https://gist.github.com/zats/ffd6b2c72b8753f043ec769c6c6739b5
// This is a port of that to Swift (For the iOS version) and a re-interpretation to make it support macOS too.
// There's a decent amount of limitations for this, like being unable to properly resize these symbols.
import SwiftUI
#if os(macOS)
class PrivateSymbol {
private let baseImage: NSImage
init?(privateSystemName name: String) {
guard let bundle = Bundle(path: "/System/Library/CoreServices/CoreGlyphsPrivate.bundle"),
let image = bundle.image(forResource: name) else {
return nil
}
self.baseImage = image
}
func imageAsset() -> Image? {
Image(nsImage: self.baseImage)
}
}
#else
class PrivateSymbol {
private let baseImage: UIImage
init?(privateSystemName name: String) {
guard let bundle = Bundle(path: "/System/Library/CoreServices/CoreGlyphsPrivate.bundle"),
let bundleClass = NSClassFromString("_UIAssetManager") as AnyObject?,
let assetManager = bundleClass.perform(NSSelectorFromString("assetManagerForBundle:"), with: bundle)?.takeUnretainedValue(),
let baseImage = assetManager.perform(NSSelectorFromString("imageNamed:"), with: name)?.takeUnretainedValue() as? UIImage else {
return nil
}
self.baseImage = baseImage.withRenderingMode(.alwaysTemplate)
}
func imageAsset() -> Image? {
return Image(uiImage: self.baseImage)
}
}
#endif
extension Image {
init?(privateSystemName: String) {
guard let privateSymbol = PrivateSymbol(privateSystemName: privateSystemName) else {
return nil
}
// .resizable() can be removed if you don't care about your symbols changing size at all
self = privateSymbol.imageAsset() ?? Image(systemName: "invalid.private.symbol") // no longer able to return nil
}
}
// You HAVE TO USE .fit() if you want your symbols to resize without stretching
extension Image {
func fit() -> some View {
self.scaledToFit().aspectRatio(contentMode: .fit)
}
}
// All in less than 54 lines! (rip to the 50 line mark but I wanted resizing.)
import SwiftUI
struct ContentView: View {
var body: some View {
Image(privateSystemName: "apple.silicon")
// Remember, .fit() and .frame() only work properly on macOS for the moment. I'm going to try to fix it on iOS soon.
.fit()
.frame(width: 50, height: 50)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment