Skip to content

Instantly share code, notes, and snippets.

@jordibruin
Last active September 21, 2023 19:41
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jordibruin/4c230f0e643d7cd59bbda653406ba3e9 to your computer and use it in GitHub Desktop.
Save jordibruin/4c230f0e643d7cd59bbda653406ba3e9 to your computer and use it in GitHub Desktop.
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