2021-02-01 11:05:34 +01:00
|
|
|
//
|
|
|
|
// Mention.swift
|
|
|
|
// CoreDataStack
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/1.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
2021-02-02 07:10:25 +01:00
|
|
|
import Foundation
|
2021-02-01 11:05:34 +01:00
|
|
|
|
2021-02-02 07:10:25 +01:00
|
|
|
public final class Mention: NSManagedObject {
|
|
|
|
public typealias ID = UUID
|
2021-04-14 09:59:29 +02:00
|
|
|
|
|
|
|
@NSManaged public private(set) var index: NSNumber
|
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
@NSManaged public private(set) var identifier: ID
|
|
|
|
@NSManaged public private(set) var id: String
|
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 username: String
|
|
|
|
@NSManaged public private(set) var acct: String
|
|
|
|
@NSManaged public private(set) var url: String
|
2021-02-02 07:10:25 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2021-02-02 07:10:25 +01:00
|
|
|
public extension Mention {
|
|
|
|
override func awakeFromInsert() {
|
|
|
|
super.awakeFromInsert()
|
2021-03-06 06:04:30 +01:00
|
|
|
|
|
|
|
setPrimitiveValue(UUID(), forKey: #keyPath(Mention.identifier))
|
2021-02-02 07:10:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
@discardableResult
|
2021-02-02 07:10:25 +01:00
|
|
|
static func insert(
|
2021-02-01 11:05:34 +01:00
|
|
|
into context: NSManagedObjectContext,
|
2021-04-14 09:59:29 +02:00
|
|
|
property: Property,
|
|
|
|
index: Int
|
2021-02-01 11:05:34 +01:00
|
|
|
) -> Mention {
|
2021-02-02 07:10:25 +01:00
|
|
|
let mention: Mention = context.insertObject()
|
2021-04-14 09:59:29 +02:00
|
|
|
mention.index = NSNumber(value: index)
|
2021-02-01 11:05:34 +01:00
|
|
|
mention.id = property.id
|
|
|
|
mention.username = property.username
|
|
|
|
mention.acct = property.acct
|
|
|
|
mention.url = property.url
|
|
|
|
return mention
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 07:10:25 +01:00
|
|
|
public extension Mention {
|
|
|
|
struct Property {
|
2021-02-01 11:05:34 +01:00
|
|
|
public let id: String
|
|
|
|
public let username: String
|
|
|
|
public let acct: String
|
|
|
|
public let url: String
|
2021-02-02 07:10:25 +01:00
|
|
|
|
2021-02-01 11:05:34 +01:00
|
|
|
public init(id: String, username: String, acct: String, url: String) {
|
|
|
|
self.id = id
|
|
|
|
self.username = username
|
|
|
|
self.acct = acct
|
|
|
|
self.url = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Mention: Managed {
|
|
|
|
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
2021-02-02 07:10:25 +01:00
|
|
|
return [NSSortDescriptor(keyPath: \Mention.createAt, ascending: false)]
|
2021-02-01 11:05:34 +01:00
|
|
|
}
|
|
|
|
}
|