Forked from jordibruin/gist:4c230f0e643d7cd59bbda653406ba3e9
Created
September 29, 2021 05:07
-
-
Save xiaoxidong/6bf1df63cb4e37ee6c9e2c0760707a6b to your computer and use it in GitHub Desktop.
Emoji grouping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSON: | |
https://unpkg.com/[email protected]/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