Skip to content

Instantly share code, notes, and snippets.

@ezefranca
Forked from mattt/recent-emoji.swift
Created September 23, 2019 01:43
Show Gist options
  • Save ezefranca/51130bda6317d27e2f00fb5b87a16d0c to your computer and use it in GitHub Desktop.
Save ezefranca/51130bda6317d27e2f00fb5b87a16d0c 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()
// ["🧐", "😨", "😱", "😤" "😡"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment