Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "reverse" lookups #4

Open
thisandagain opened this issue Jan 7, 2014 · 2 comments
Open

Add support for "reverse" lookups #4

thisandagain opened this issue Jan 7, 2014 · 2 comments
Labels

Comments

@thisandagain
Copy link
Contributor

Re: GH-3

@pizthewiz
Copy link

How about using the existing emojiAliases dictionary and constructing the reverse, something like:

+ (NSDictionary *)reverseEmojiAliases {
    static NSDictionary *_reverseEmojiAliases;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSMutableDictionary *map = [[NSMutableDictionary alloc] init];
        NSSet* uniqueEmoji = [NSSet setWithArray:[[self emojiAliases] allValues]];
        [uniqueEmoji enumerateObjectsUsingBlock:^(NSString *emoji, BOOL *stop) {
            NSString* code = [[[self emojiAliases] allKeysForObject:emoji] firstObject];
            map[emoji] = code;
        }];
        _reverseEmojiAliases = [[NSDictionary alloc] initWithDictionary:map];
    });
    return _reverseEmojiAliases;
}

@sibahota059
Copy link

How about this?

-(NSDictionary *)reverseEmojiAliases {
NSMutableDictionary *_revEmojiAliases = [NSMutableDictionary new];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    for (NSString *key in [EMOJI_HASH allKeys]) {
        _revEmojiAliases[EMOJI_HASH[key]] = key;
    }
});
return _revEmojiAliases;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants