Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
// ["🧐", "😨", "😱", "😤" "😡"]
@SpectralDragon

This comment has been minimized.

Copy link

SpectralDragon commented Nov 9, 2019

preferences.dictionary(forKey: "EmojiDefaultsKey") doesn't work on iOS 13.2, but EMFDefaultsKey works great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.