Having problem getting custom SF symbol to load

So in my app, I need to use a custom SF symbol. It is a very simple symbol, I simply exported the g.square.fill emblem, and had it updated with the letters GF in the square instead of just G. Renamed it to gf.square.fill and it validated in SF symbols.

I then copied over the SVG file to my assets folder. Normally, when you call an SF symbol you use the following syntax:

Image(systemName: “ticket.fill”)
.foregroundColor(.green)
.font(.caption2)

However, from what I read when it is a custom SF symbol in assets, you use the following syntax:


Image(“gf.square.fill”)
.foregroundColor(.orange)
.font(.caption2)

In any case I have tried it both ways and get the same results. It is as if the file does not exist. The name of the file in assets is correct and I know the code is good because if I change the name to g.sqaure.fill, it shows the g in the square sf symbol that is in the standard library. It is like it is calling a file that does not exist.

Just wondering if anyone has any ideas on why it does not display.
Thanks

@kboone

Hi Ken,

Welcome to the community.

That’s correct. There could be an issue with the symbol you have saved in your assets folder. Can you post a screenshot of how it looks in your assets folder.

Sure, here is a screenshot of the the symbol in the assets folder.

Did you follow these guidelines when creating your custom symbol?

Yes and from what I read, XCODE will also validate that it is a valid SVG symbol when you copy it over to assets and generate an error message if not. I understand that if it wasn’t done properly, the symbol might show up funky or not what you expect. In my case, it never even takes up space in the view, as if it does not recognize the filename of the asset.

I managed to edit the g.square.fill symbol in Sketch by also downloading f.square.fill and copying and moving around the respective paths.

I saved the sketch file and exported the new symbol as an SVG and dragged it into Xcode. Works perfectly so I have learned something new in the process. Thanks for posting the question and initiating a challenge for me. I can post the SVG file to you if you like.

1 Like

Chris,
Thank you so much! I have never edited SVG files so I must have screwed something up. Yours worked perfectly. I really appreciate the help with that.
Thank you again!

1 Like

No problem Ken.

1 Like