mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-11 07:43:28 +01:00
Switches to Core Data model objects
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14490.99" systemVersion="18D109" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="App" representedClassName="App" syncable="YES">
|
||||
<attribute name="developerName" attributeType="String" syncable="YES"/>
|
||||
<attribute name="iconName" attributeType="String" syncable="YES"/>
|
||||
<attribute name="identifier" attributeType="String" syncable="YES"/>
|
||||
<attribute name="localizedDescription" attributeType="String" syncable="YES"/>
|
||||
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||
<attribute name="screenshotNames" attributeType="Transformable" syncable="YES"/>
|
||||
<uniquenessConstraints>
|
||||
<uniquenessConstraint>
|
||||
<constraint value="identifier"/>
|
||||
</uniquenessConstraint>
|
||||
</uniquenessConstraints>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="App" positionX="-63" positionY="-18" width="128" height="135"/>
|
||||
</elements>
|
||||
</model>
|
||||
@@ -2,20 +2,66 @@
|
||||
// App.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/9/19.
|
||||
// Created by Riley Testut on 5/20/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
class App: NSObject, Codable
|
||||
@objc(App)
|
||||
class App: NSManagedObject, Decodable
|
||||
{
|
||||
var name: String
|
||||
var subtitle: String
|
||||
var developer: String
|
||||
/* Properties */
|
||||
@NSManaged private(set) var name: String
|
||||
@NSManaged private(set) var identifier: String
|
||||
|
||||
var localizedDescription: String
|
||||
@NSManaged private(set) var developerName: String
|
||||
@NSManaged private(set) var localizedDescription: String
|
||||
|
||||
var iconName: String
|
||||
var screenshotNames: [String]
|
||||
@NSManaged private(set) var iconName: String
|
||||
@NSManaged private(set) var screenshotNames: [String]
|
||||
|
||||
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
|
||||
{
|
||||
super.init(entity: entity, insertInto: context)
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey
|
||||
{
|
||||
case name
|
||||
case identifier
|
||||
case developerName
|
||||
case localizedDescription
|
||||
case iconName
|
||||
case screenshotNames
|
||||
}
|
||||
|
||||
required init(from decoder: Decoder) throws
|
||||
{
|
||||
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
||||
|
||||
super.init(entity: App.entity(), insertInto: nil)
|
||||
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.name = try container.decode(String.self, forKey: .name)
|
||||
self.identifier = try container.decode(String.self, forKey: .identifier)
|
||||
self.developerName = try container.decode(String.self, forKey: .developerName)
|
||||
self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription)
|
||||
|
||||
self.iconName = try container.decode(String.self, forKey: .iconName)
|
||||
self.screenshotNames = try container.decodeIfPresent([String].self, forKey: .screenshotNames) ?? []
|
||||
|
||||
context.insert(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
extension App
|
||||
{
|
||||
@nonobjc class func fetchRequest() -> NSFetchRequest<App>
|
||||
{
|
||||
return NSFetchRequest<App>(entityName: "App")
|
||||
}
|
||||
}
|
||||
|
||||
48
AltStore/Model/DatabaseManager.swift
Normal file
48
AltStore/Model/DatabaseManager.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// DatabaseManager.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/20/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
|
||||
import Roxas
|
||||
|
||||
public class DatabaseManager
|
||||
{
|
||||
public static let shared = DatabaseManager()
|
||||
|
||||
public let persistentContainer: RSTPersistentContainer
|
||||
|
||||
public private(set) var isStarted = false
|
||||
|
||||
private init()
|
||||
{
|
||||
self.persistentContainer = RSTPersistentContainer(name: "AltStore")
|
||||
}
|
||||
}
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
func start(completionHandler: @escaping (Error?) -> Void)
|
||||
{
|
||||
guard !self.isStarted else { return completionHandler(nil) }
|
||||
|
||||
self.persistentContainer.loadPersistentStores { (description, error) in
|
||||
guard error == nil else { return completionHandler(error!) }
|
||||
|
||||
self.isStarted = true
|
||||
|
||||
completionHandler(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
var viewContext: NSManagedObjectContext {
|
||||
return self.persistentContainer.viewContext
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user