Skip to content

Instantly share code, notes, and snippets.

@mattt
Created September 22, 2019 16:47
Show Gist options
  • Save mattt/aff7fb9676389b87e50437e950b6a12e to your computer and use it in GitHub Desktop.
Save mattt/aff7fb9676389b87e50437e950b6a12e to your computer and use it in GitHub Desktop.
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
Copy link

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