Skip to content

Instantly share code, notes, and snippets.

Last active Feb 2, 2018
What would you like to do?
Extract emoji by category using the EmojiFoundation framework
"People" : [
"๐Ÿ˜ ",
"๐Ÿค ",
"โ˜ ๏ธ",
"๐Ÿง ",
"๐Ÿ‘ ",
"Activity" : [
"Nature" : [
"๐Ÿ ",
"FoodAndDrink" : [
"๐Ÿ ",
"๐Ÿฅ ",
"Objects" : [
"๐Ÿ“ ",
"๐Ÿ› ",
"Flags" : [
"๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ",
"๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ",
"๐Ÿด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ",
"Symbols" : [
"โš ๏ธ",
"๐Ÿ’ ",
"๐Ÿ” ",
"โ™ ๏ธ",
"๐Ÿ• ",
"TravelAndPlaces" : [
"๐Ÿš ",
"๐ŸŽ ",
"๐Ÿ ",
"๐ŸŒ ",
#import <Foundation/Foundation.h>
@interface NSObject (EMFEmojiCategory)
- (NSArray *) categoryIdentifierList;
- (NSArray *) _emojiSetForIdentifier:(NSString *)identifier;
int ExtractEmoji(NSString *emojiFoundationPath)
NSBundle *emojiFoundationBundle = [NSBundle bundleWithURL:[NSURL fileURLWithPath:emojiFoundationPath]];
if (!emojiFoundationBundle)
NSLog(@"The EmojiFoundation framework does not exist at %@", emojiFoundationPath);
return 1;
NSError *loadError;
if (![emojiFoundationBundle loadAndReturnError:&loadError])
NSLog(@"Failed to load %@: %@", emojiFoundationBundle, loadError);
return 2;
Class EMFEmojiCategory = NSClassFromString(@"EMFEmojiCategory");
if (!EMFEmojiCategory)
NSLog(@"EMFEmojiCategory class not found.");
return 3;
NSArray *categoryIdentifiers = [EMFEmojiCategory categoryIdentifierList];
if (categoryIdentifiers.count == 0)
NSLog(@"+[EMFEmojiCategory categoryIdentifierList] returned an empty list.");
return 4;
NSMutableDictionary *emoji = [NSMutableDictionary new];
for (NSString *categoryIdentifier in categoryIdentifiers)
NSString *identifier = [categoryIdentifier stringByReplacingOccurrencesOfString:@"EMFEmojiCategory" withString:@""];
NSArray *emojiSet = [EMFEmojiCategory _emojiSetForIdentifier:categoryIdentifier];
if (emojiSet.count > 0)
emoji[identifier] = emojiSet;
NSError *writeError;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:emoji options:NSJSONWritingPrettyPrinted error:&writeError];
if (jsonData)
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
printf("%s", json.UTF8String);
NSLog(@"Failed to serialize emoji dictionary: %@", writeError);
return 5;
return 0;
int main(int argc, const char * argv[])
NSString *emojiFoundationPath = argc >= 2 ? @(argv[1]) : @"/System/Library/PrivateFrameworks/EmojiFoundation.framework";
return ExtractEmoji(emojiFoundationPath);
default: EmojiFoundationExtractor
./EmojiFoundationExtractor > Emoji.json
clang $@.m -o $@ -fobjc-arc
rm -f EmojiFoundationExtractor

This comment has been minimized.

Copy link

@nst nst commented Jan 19, 2018

FWIW, a Python version:

#!/usr/bin/env python2.7

from Foundation import NSBundle, NSClassFromString
import json, io


EC = NSClassFromString("EMFEmojiCategory")

ids = EC.categoryIdentifierList()

d = {id.lstrip("EMFEmojiCategory"): list(EC._emojiSetForIdentifier_(id)) for id in ids}

with'out.json', 'w') as f:
    f.write(unicode(json.dumps(d, indent=4, ensure_ascii=False)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment