This commit is contained in:
John Estropia
2020-08-19 08:32:18 +09:00
parent 204c4de1f6
commit d75029f54b
7 changed files with 28 additions and 16 deletions

View File

@@ -64,7 +64,7 @@ class ConvenienceTests: BaseTestCase {
self.prepareStack { (stack) in
_ = withExtendedLifetime(stack.beginUnsafe()) { (transaction: UnsafeDataTransaction) in
withExtendedLifetime(stack.beginUnsafe()) { (transaction: UnsafeDataTransaction) in
let controller = transaction.createFetchedResultsController(
From<TestEntity1>(),

View File

@@ -32,7 +32,7 @@ extension Modern.PlacemarksDemo {
"annotation",
customGetter: { object, field in
Annotation(
Modern.PlacemarksDemo.Place.Annotation(
latitude: object.$latitude.value,
longitude: object.$longitude.value,
title: object.$title.value,
@@ -47,7 +47,7 @@ extension Modern.PlacemarksDemo {
object.$subtitle.value = nil
}
)
var annotation: Annotation
var annotation: Modern.PlacemarksDemo.Place.Annotation
func setRandomLocation() {
@@ -57,7 +57,7 @@ extension Modern.PlacemarksDemo {
self.subtitle = nil
}
// MARK: - Annotation
// MARK: - Modern.PlacemarksDemo.Place.Annotation
final class Annotation: NSObject, MKAnnotation {

View File

@@ -32,13 +32,15 @@ extension Modern.PokedexDemo {
// MARK: View
var body: some View {
List() {
ScrollView {
ForEach(self.pokedexEntries.snapshot, id: \.self) { pokedexEntry in
LazyView {
Text(pokedexEntry.snapshot?.$id ?? "")
Text(pokedexEntry.snapshot?.$name ?? "")
}
.frame(height: 100)
}
}
.frame(minWidth: 0, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
.overlay(
InstructionsView(
("Random", "Sets random coordinate"),
@@ -61,6 +63,7 @@ extension Modern.PokedexDemo {
#if DEBUG
@available(iOS 14.0, *)
struct _Demo_Modern_PokedexDemo_MainView_Preview: PreviewProvider {
// MARK: PreviewProvider

View File

@@ -13,9 +13,12 @@ extension Modern.PokedexDemo {
final class PokedexEntry: CoreStoreObject, ImportableUniqueObject {
// MARK: Internal
@Field.Stored("id")
var id: String = ""
var id: Int = 0
@Field.Stored("name")
var name: String = ""
@Field.Stored("url")
var url: URL!
@@ -27,14 +30,16 @@ extension Modern.PokedexDemo {
// MARK: ImportableObject
typealias ImportSource = Dictionary<String, Any>
typealias ImportSource = (index: Int, json: Dictionary<String, Any>)
// MARK: ImportableUniqueObject
typealias UniqueIDType = Int
static let uniqueIDKeyPath: String = String(keyPath: \Modern.PokedexDemo.PokedexEntry.$id)
var uniqueIDValue: String {
var uniqueIDValue: UniqueIDType {
get {
@@ -46,14 +51,16 @@ extension Modern.PokedexDemo {
}
}
static func uniqueID(from source: ImportSource, in transaction: BaseDataTransaction) throws -> String? {
static func uniqueID(from source: ImportSource, in transaction: BaseDataTransaction) throws -> UniqueIDType? {
return try Modern.PokedexDemo.Service.parseJSON(source["name"])
return source.index + 1
}
func update(from source: ImportSource, in transaction: BaseDataTransaction) throws {
self.url = URL(string: try Modern.PokedexDemo.Service.parseJSON(source["url"]))
let json = source.json
self.name = try Modern.PokedexDemo.Service.parseJSON(json["name"])
self.url = URL(string: try Modern.PokedexDemo.Service.parseJSON(json["url"]))
}
}
}

View File

@@ -128,7 +128,9 @@ extension Modern.PokedexDemo {
_ = try transaction.importUniqueObjects(
Into<Modern.PokedexDemo.PokedexEntry>(),
sourceArray: results
sourceArray: results.enumerated().map { (index, json) in
(index: index, json: json)
}
)
},
success: { result in

View File

@@ -779,7 +779,7 @@ public final class CoreStoreSchema: DynamicSchema {
)
}
_ = allFieldCoders
allFieldCoders
.flatMap({ (_, values) in values })
.reduce(
into: [:] as [NSValueTransformerName: Internals.AnyFieldCoder],

View File

@@ -457,7 +457,7 @@ extension DataStack {
DispatchQueue.main.async {
_ = withExtendedLifetime(childProgress) { (_: Progress) -> Void in }
withExtendedLifetime(childProgress) { (_: Progress) -> Void in }
}
}
)