Files
SideStore/Sources/SideStoreCore/Model/Account.swift

61 lines
1.5 KiB
Swift
Raw Normal View History

//
// Account.swift
// AltStore
//
// Created by Riley Testut on 6/5/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import CoreData
2023-03-01 00:48:36 -05:00
import Foundation
import AltSign
@objc(Account)
2023-03-01 00:48:36 -05:00
public class Account: NSManagedObject, Fetchable {
public var localizedName: String {
var components = PersonNameComponents()
2023-03-01 00:48:36 -05:00
components.givenName = firstName
components.familyName = lastName
let name = PersonNameComponentsFormatter.localizedString(from: components, style: .default)
return name
}
2023-03-01 00:48:36 -05:00
/* Properties */
@NSManaged public var appleID: String
@NSManaged public var identifier: String
2023-03-01 00:48:36 -05:00
@NSManaged public var firstName: String
@NSManaged public var lastName: String
2023-03-01 00:48:36 -05:00
@NSManaged public var isActiveAccount: Bool
2023-03-01 00:48:36 -05:00
/* Relationships */
@NSManaged public var teams: Set<Team>
2023-03-01 00:48:36 -05:00
override private init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
2023-03-01 00:48:36 -05:00
public init(_ account: ALTAccount, context: NSManagedObjectContext) {
super.init(entity: Account.entity(), insertInto: context)
2023-03-01 00:48:36 -05:00
update(account: account)
}
2023-03-01 00:48:36 -05:00
public func update(account: ALTAccount) {
appleID = account.appleID
identifier = account.identifier
firstName = account.firstName
lastName = account.lastName
}
}
2023-03-01 00:48:36 -05:00
public extension Account {
@nonobjc class func fetchRequest() -> NSFetchRequest<Account> {
NSFetchRequest<Account>(entityName: "Account")
}
}