FontAwesomeKit icon indicating copy to clipboard operation
FontAwesomeKit copied to clipboard

Reliable method to look up icon by name

Open keyboardsamurai opened this issue 9 years ago • 14 comments

Since the method to look up an icon by name as discussed in #37 is buggy, it would be nice to have a reliable method for said lookup.

keyboardsamurai avatar Jul 18 '15 20:07 keyboardsamurai

Before adding this feature, I'm wondering why you need it. I've never actually need this feature in my project. The reason I added this method is I want to add some debugging support. Do you want to save the icon's name as some kind of configuration and recreate that icon later? In that case I think I should implement NSCoding on FAKIcon so an icon can be archived.

PrideChung avatar Jul 19 '15 14:07 PrideChung

It's exactly that - I am configuring a list of labels by providing them with a serialized json feed from a server. Since I want the user to be able to pick an icon, I have to send the name of the icon over the wire somehow. It would be awesome having this functionality.

keyboardsamurai avatar Jul 20 '15 10:07 keyboardsamurai

@keyboardsamurai @PrideChung second this, I also encountered this issue. Enumerating through [FAKFontAwesome allIcons] also do not show some icon names. I have a configuration that holds which icon to use by icon name. It'll be awesome if you add/fix this feature! Thanks!

davidck avatar Jul 29 '15 04:07 davidck

I also encountered this issue but in my case, I received the font awesome string from the server and had to do the translation to properly display the icon.

GabrielCartier avatar Sep 17 '15 23:09 GabrielCartier

+1, I have dozens of items, each has different icon. I put them in a JSON file (and updatable from server). name lookup will help greatly for this scenario. Thanks!

top2tech avatar Sep 18 '15 23:09 top2tech

Another library has name look up: https://github.com/alexdrone/ios-fontawesome But I want to stick to this library.

top2tech avatar Sep 18 '15 23:09 top2tech

@top2tech Do you need to save any other property into the JSON file, like icon color and the size?

PrideChung avatar Sep 20 '15 13:09 PrideChung

I guess the other properties can be used in other ways. If they have size and color, it's easy to actually create the icon properly knowing those. The main issue is the name lookup.

I don't think adding the other properties would be useful with the existing methods.

GabrielCartier avatar Sep 21 '15 21:09 GabrielCartier

Yes, the issue is name lookup. I'm currently using the output as an attributed string and configure it separately, so no urgent need for icon color/size. Not being able to lookup some of these icons is actually creeping up on me since our designer heavily relies on icons from FontAwesome. I'm currently hardcoding these until it's fixed.

davidck avatar Sep 21 '15 22:09 davidck

Same here, I have implemented a few of them, is there anything preventing a simple lookupMethod?

I can do it and send a PR if @PrideChung doesn't have the time.

GabrielCartier avatar Sep 21 '15 23:09 GabrielCartier

@GabrielCartier I'm busy for baby sitting lately, you would do us a big favor if you can implement this.

PrideChung avatar Sep 22 '15 07:09 PrideChung

@GabrielCartier Looking at FAKFontAwesome.m, I think the simplest way would be to ensure [FAKFontAwesome allIcons] has no duplicates and that all icons would have correct mapping to its matching class method.

The long way would be to change the code scheme to match the Font Awesome web scheme. i.e. <i class="fa fa-star-o"></i>

So instead of @"\uf006", I'd propose @"fa-star-o".

davidck avatar Sep 22 '15 15:09 davidck

Perhaps we can create a separate lookup method to fetch the appropriate class method to perform selector. ex: FAKFontAwesome *icon = [FAKFontAwesome iconWithLookup:@"fa-star-o" size:18.0f];

something like:

+ (instancetype)iconWithLookup:(NSString *)webIdentifier size:(CGFloat)size { 
    // String manipulation with webIdentifier
    NSString *classMethod = doSomething();  // ex: fa-star-o would output starOIconWithSize
    return [self performSelector:@selector(classMethod)];
}

davidck avatar Sep 22 '15 15:09 davidck

Yea, that's what I was thinking. I'll write it today if I got time and do a PR

GabrielCartier avatar Sep 22 '15 15:09 GabrielCartier