Add support for SPM
This commit is contained in:
@@ -11,10 +11,10 @@ let package = Package(
|
|||||||
name: "EmojiKit",
|
name: "EmojiKit",
|
||||||
targets: ["EmojiKit"]
|
targets: ["EmojiKit"]
|
||||||
),
|
),
|
||||||
// .library(
|
.library(
|
||||||
// name: "EmojiKitLibrary",
|
name: "EmojiKitLibrary",
|
||||||
// targets: ["EmojiKitLibrary"]
|
targets: ["EmojiKitLibrary"]
|
||||||
// )
|
)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"),
|
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"),
|
||||||
@@ -26,8 +26,8 @@ let package = Package(
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||||
.product(name: "SwiftSoup", package: "SwiftSoup"),
|
.product(name: "SwiftSoup", package: "SwiftSoup"),
|
||||||
// .target(name: "EmojiKitLibrary")
|
.target(name: "EmojiKitLibrary")
|
||||||
]),
|
]),
|
||||||
// .target(name: "EmojiKitLibrary")
|
.target(name: "EmojiKitLibrary")
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import EmojiKitLibrary
|
||||||
|
|
||||||
public enum DataProcessor {
|
public enum DataProcessor {
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
//
|
|
||||||
// EmojiCategory.swift
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Created by Niklas Amslgruber on 10.06.23.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
public class EmojiCategory: Codable {
|
|
||||||
|
|
||||||
public enum Name: String, CaseIterable, Codable {
|
|
||||||
case flags = "Flags"
|
|
||||||
case activities = "Activities"
|
|
||||||
case components = "Component"
|
|
||||||
case objects = "Objects"
|
|
||||||
case travelAndPlaces = "Travel & Places"
|
|
||||||
case symbols = "Symbols"
|
|
||||||
case peopleAndBody = "People & Body"
|
|
||||||
case animalsAndNature = "Animals & Nature"
|
|
||||||
case foodAndDrink = "Food & Drink"
|
|
||||||
case smileysAndEmotions = "Smileys & Emotion"
|
|
||||||
}
|
|
||||||
|
|
||||||
public let name: Name
|
|
||||||
public let values: [String]
|
|
||||||
|
|
||||||
public init(name: Name, values: [String]) {
|
|
||||||
self.name = name
|
|
||||||
self.values = values
|
|
||||||
}
|
|
||||||
}
|
|
||||||
62
Sources/EmojiKitLibrary/EmojiCategory.swift
Normal file
62
Sources/EmojiKitLibrary/EmojiCategory.swift
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
//
|
||||||
|
// EmojiCategory.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Niklas Amslgruber on 10.06.23.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public class EmojiCategory: Codable {
|
||||||
|
|
||||||
|
public enum Name: String, CaseIterable, Codable {
|
||||||
|
case flags = "Flags"
|
||||||
|
case activities = "Activities"
|
||||||
|
case components = "Component"
|
||||||
|
case objects = "Objects"
|
||||||
|
case travelAndPlaces = "Travel & Places"
|
||||||
|
case symbols = "Symbols"
|
||||||
|
case peopleAndBody = "People & Body"
|
||||||
|
case animalsAndNature = "Animals & Nature"
|
||||||
|
case foodAndDrink = "Food & Drink"
|
||||||
|
case smileysAndEmotions = "Smileys & Emotion"
|
||||||
|
|
||||||
|
public static var orderedCases: [EmojiCategory.Name] {
|
||||||
|
return EmojiCategory.Name.allCases.sorted(by: { $0.order < $1.order })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order that Apple uses in their emoji picker
|
||||||
|
public var order: Int {
|
||||||
|
switch self {
|
||||||
|
case .flags:
|
||||||
|
return 10
|
||||||
|
case .activities:
|
||||||
|
return 5
|
||||||
|
case .components:
|
||||||
|
return 8
|
||||||
|
case .objects:
|
||||||
|
return 7
|
||||||
|
case .travelAndPlaces:
|
||||||
|
return 6
|
||||||
|
case .symbols:
|
||||||
|
return 9
|
||||||
|
case .peopleAndBody:
|
||||||
|
return 2
|
||||||
|
case .animalsAndNature:
|
||||||
|
return 3
|
||||||
|
case .foodAndDrink:
|
||||||
|
return 4
|
||||||
|
case .smileysAndEmotions:
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public let name: Name
|
||||||
|
public let values: [String]
|
||||||
|
|
||||||
|
public init(name: Name, values: [String]) {
|
||||||
|
self.name = name
|
||||||
|
self.values = values
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,17 +7,17 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum EmojiManager {
|
public enum EmojiManager {
|
||||||
|
|
||||||
enum Version: Int {
|
public enum Version: Int {
|
||||||
case v14 = 14
|
case v14 = 14
|
||||||
case v15 = 15
|
case v15 = 15
|
||||||
|
|
||||||
var fileName: String {
|
public var fileName: String {
|
||||||
return "emojis_v\(rawValue)"
|
return "emojis_v\(rawValue)"
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getSupportedVersion() -> Version {
|
public static func getSupportedVersion() -> Version {
|
||||||
if #available(iOS 16.4, *) {
|
if #available(iOS 16.4, *) {
|
||||||
return .v15
|
return .v15
|
||||||
} else {
|
} else {
|
||||||
@@ -25,13 +25,18 @@ enum EmojiManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func getAvailableEmojis(version: Version = .getSupportedVersion()) -> [EmojiCategory] {
|
/// Returns all emojis for a specific version
|
||||||
|
/// - Parameters:
|
||||||
|
/// - version: The specific version you want to fetch (default: the highest supported version for a device's iOS version)
|
||||||
|
/// - showAllVariations: Some emojis inlcude skin type variations which increases the number of emojis drastically. (default: only the yellow neutral emojis are returned)
|
||||||
|
/// - Returns: Array of categories with all emojis that are assigned to each category
|
||||||
|
public static func getAvailableEmojis(version: Version = .getSupportedVersion(), showAllVariations: Bool = false) -> [EmojiCategory] {
|
||||||
if let url = Bundle.main.url(forResource: version.fileName, withExtension: "json"), let content = try? Data(contentsOf: url), let result = try? JSONDecoder().decode([EmojiCategory].self, from: content) {
|
if let url = Bundle.main.url(forResource: version.fileName, withExtension: "json"), let content = try? Data(contentsOf: url), let result = try? JSONDecoder().decode([EmojiCategory].self, from: content) {
|
||||||
var filteredEmojis: [EmojiCategory] = []
|
var filteredEmojis: [EmojiCategory] = []
|
||||||
for category in result {
|
for category in result {
|
||||||
let supportedEmojis = category.values.filter({
|
let supportedEmojis = category.values.filter({
|
||||||
isNeutralEmoji(for: $0)
|
showAllVariations ? true : isNeutralEmoji(for: $0)
|
||||||
})
|
})
|
||||||
filteredEmojis.append(EmojiCategory(name: category.name, values: supportedEmojis))
|
filteredEmojis.append(EmojiCategory(name: category.name, values: supportedEmojis))
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user