8

I am working on an app that shows all the features available in SwiftUI. As part of it, I wanted to display all the SF Symbols that are available. I was wondering if there was a way to do it easily (without needing to type up all the names/variations).

Thanks

Thomas Braun
  • 1,109
  • 2
  • 13
  • 27

3 Answers3

12

You can copy them from SF Symbols app (cmd+A to select all, and cmd+shift+c to copy all the names, paste to a text file, and refactor the names to Image(systemName: "NAME") easily.

AlbertUI
  • 1,409
  • 9
  • 26
  • Damn. Didn't even realize that was possible. What do you recommend as the best way to refactor it to get the code to be able to iterate through all of them? – Thomas Braun Aug 10 '20 at 02:25
  • With Xcode you can :) (but I think you'll want to split all the symbols in 4-5 fragments, because could be a bit slow to edit all of them at the same time). You can check the xcode multicursor here: https://stackoverflow.com/questions/50696995/multi-cursor-editing-in-xcode-10 – AlbertUI Aug 12 '20 at 21:18
4

Here is how it's possible. No warranty of any kind for this code on passing the App Store review process.

if let sfSymbolsBundle = Bundle(identifier: "com.apple.SFSymbolsFramework"),
    let bundlePath = sfSymbolsBundle.path(forResource: "CoreGlyphs", ofType: "bundle"),
    let bundle = Bundle(path: bundlePath),
    let resourcePath = bundle.path(forResource: "symbol_search", ofType: "plist"),
    let plist = NSDictionary(contentsOfFile: resourcePath) {

    /// keys in plist are names of all available symbols

}
Eugene Dudnyk
  • 5,553
  • 1
  • 23
  • 48
  • 1
    Not working on iOS 16.2 simulator – Richard Witherspoon Mar 22 '23 at 04:49
  • @RichardWitherspoon I've just tested - it works on iOS 16.2 simulator. To reproduce, simply invoke in the debugger `po NSDictionary(contentsOfFile: Bundle(identifier: "com.apple.CoreGlyphs")!.path(forResource: "symbol_search", ofType: "plist")!)` – Eugene Dudnyk Mar 23 '23 at 03:14
  • I get `nil` for `Bundle(identifier: "com.apple.CoreGlyphs")` on iOS. But on macOS it works . Using Xcode 14.3 (14E222b) on macOS 13.3.1 (22E261). – Klaas Apr 24 '23 at 10:17
  • On macOS 13.3 the bundle can be found at `/System/Library/PrivateFrameworks/SFSymbols.framework/Versions/A/Resources/CoreGlyphs.bundle` – Klaas Apr 24 '23 at 14:00
  • @Klaas Since SFSymbols framework is the bundle that can be found with dyld cache, maybe working solution would be to find CoreGlyphs bundle in resources of SFSymbols framework bundle. Updated the answer. – Eugene Dudnyk Apr 24 '23 at 14:46
0

The above answer doesn't work but it was helpful in pointing me towards a solution that does (at least for the Mac).

if let bundle = Bundle(identifier: "com.apple.CoreGlyphs"),
   let resourcePath = bundle.path(forResource: "symbol_search", ofType: "plist"),
   let plist = NSDictionary(contentsOfFile: resourcePath) {
    // use the plist to access the symbol where the key is the symbol string and value is a list of key words
}