-
-
Save ezefranca/51130bda6317d27e2f00fb5b87a16d0c to your computer and use it in GitHub Desktop.
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
import Foundation | |
extension Character { | |
var isEmoji: Bool { | |
return unicodeScalars.allSatisfy { $0.properties.isEmoji } | |
} | |
} | |
func recentlyUsedEmoji() -> [Character]? { | |
#if os(iOS) | |
let preferences = UserDefaults(suiteName: "com.apple.EmojiPreferences")! | |
guard let emojiDefaults = preferences.dictionary(forKey: "EmojiDefaultsKey"), | |
let emojiRecentsDefaults = emojiDefaults["EmojiRecentsDefaultsKey"] as? [String: Any], | |
let recents = emojiRecentsDefaults["RecentsKey"] as? [String] | |
else { | |
return nil | |
} | |
#elseif os(macOS) | |
let preferences = UserDefaults(suiteName: "com.apple.EmojiPreferences")! | |
guard let defaults = preferences.dictionary(forKey: "EMFDefaultsKey"), | |
let recents = defaults["EMFRecentsKey"] as? [String] | |
else { | |
return nil | |
} | |
#else | |
return nil | |
#endif | |
return recents.compactMap(Character.init) | |
.filter { $0.isEmoji } | |
} | |
recentlyUsedEmoji() | |
// ["🧐", "😨", "😱", "😤" "😡"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment