2021-02-01 11:05:34 +01:00
|
|
|
//
|
|
|
|
// Emoji.swift
|
|
|
|
// CoreDataStack
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/1.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public final class Emoji: NSManagedObject {
|
2021-02-02 07:10:25 +01:00
|
|
|
public typealias ID = UUID
|
2021-02-01 11:05:34 +01:00
|
|
|
@NSManaged public private(set) var identifier: ID
|
2021-02-02 07:10:25 +01:00
|
|
|
@NSManaged public private(set) var createAt: Date
|
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
@NSManaged public private(set) var shortcode: String
|
|
|
|
@NSManaged public private(set) var url: String
|
|
|
|
@NSManaged public private(set) var staticURL: String
|
|
|
|
@NSManaged public private(set) var visibleInPicker: Bool
|
2021-02-02 07:10:25 +01:00
|
|
|
@NSManaged public private(set) var category: String?
|
|
|
|
|
|
|
|
// many-to-one relationship
|
2021-04-01 08:39:15 +02:00
|
|
|
@NSManaged public private(set) var status: Status?
|
2021-02-01 11:05:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public extension Emoji {
|
2021-02-02 07:10:25 +01:00
|
|
|
override func awakeFromInsert() {
|
|
|
|
super.awakeFromInsert()
|
2021-03-06 06:04:30 +01:00
|
|
|
setPrimitiveValue(UUID(), forKey: #keyPath(Emoji.identifier))
|
2021-02-02 07:10:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
@discardableResult
|
|
|
|
static func insert(
|
|
|
|
into context: NSManagedObjectContext,
|
|
|
|
property: Property
|
|
|
|
) -> Emoji {
|
|
|
|
let emoji: Emoji = context.insertObject()
|
|
|
|
emoji.shortcode = property.shortcode
|
|
|
|
emoji.url = property.url
|
|
|
|
emoji.staticURL = property.staticURL
|
|
|
|
emoji.visibleInPicker = property.visibleInPicker
|
|
|
|
return emoji
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Emoji {
|
|
|
|
struct Property {
|
|
|
|
|
|
|
|
public let shortcode: String
|
|
|
|
public let url: String
|
|
|
|
public let staticURL: String
|
|
|
|
public let visibleInPicker: Bool
|
2021-02-02 07:10:25 +01:00
|
|
|
public let category: String?
|
2021-02-01 11:05:34 +01:00
|
|
|
|
2021-02-02 07:10:25 +01:00
|
|
|
public init(shortcode: String, url: String, staticURL: String, visibleInPicker: Bool, category: String?) {
|
2021-02-01 11:05:34 +01:00
|
|
|
self.shortcode = shortcode
|
|
|
|
self.url = url
|
|
|
|
self.staticURL = staticURL
|
|
|
|
self.visibleInPicker = visibleInPicker
|
2021-02-02 07:10:25 +01:00
|
|
|
self.category = category
|
2021-02-01 11:05:34 +01:00
|
|
|
}
|
2021-02-02 07:10:25 +01:00
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Emoji: Managed {
|
|
|
|
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
2021-02-02 07:10:25 +01:00
|
|
|
return [NSSortDescriptor(keyPath: \Emoji.createAt, ascending: false)]
|
2021-02-01 11:05:34 +01:00
|
|
|
}
|
|
|
|
}
|