Created
September 22, 2019 16:47
-
-
Save mattt/aff7fb9676389b87e50437e950b6a12e 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
preferences.dictionary(forKey: "EmojiDefaultsKey")
doesn't work on iOS 13.2, butEMFDefaultsKey
works great