Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Emoji grouping
JSON:
https://unpkg.com/emoji.json@13.1.0/emoji.json
class EmojiManager: ObservableObject {
@Published var emojis: [EmojiObject] = []
init() {
decodeJSON()
}
func decodeJSON() {
if let url = Bundle.main.url(forResource: "emoji", withExtension: "json") {
do {
let data = try Data(contentsOf: url)
let emoji: [EmojiObject] = try! JSONDecoder().decode([EmojiObject].self, from: data)
self.emojis = emoji
} catch {
print("error:\(error)")
}
}
}
}
struct EmojiObject: Decodable, Hashable, Identifiable {
let codes, char, name, category: String
let subgroup: String
let group: EmojiGroup
var id: String { codes }
}
enum EmojiGroup: String, CaseIterable, Codable, Identifiable {
case smileys = "Smileys & Emotion"
case people = "People & Body"
case component = "Component"
case animals = "Animals & Nature"
case foodAndDrink = "Food & Drink"
case travel = "Travel & Places"
case activities = "Activities"
case objects = "Objects"
case symbols = "Symbols"
case flags = "Flags"
var id: String { rawValue }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment