From d75029f54b8ce43d20e5757b279a383d5556b706 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 19 Aug 2020 08:32:18 +0900 Subject: [PATCH] WIP --- CoreStoreTests/ConvenienceTests.swift | 2 +- .../Modern.PlacemarksDemo.Place.swift | 6 +++--- .../Modern.PokedexDemo.MainView.swift | 7 +++++-- .../Modern.PokedexDemo.PokedexEntry.swift | 21 ++++++++++++------- .../Modern.PokedexDemo.Service.swift | 4 +++- Sources/CoreStoreSchema.swift | 2 +- Sources/DataStack+Migration.swift | 2 +- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CoreStoreTests/ConvenienceTests.swift b/CoreStoreTests/ConvenienceTests.swift index 5f605de..9e7fd2e 100644 --- a/CoreStoreTests/ConvenienceTests.swift +++ b/CoreStoreTests/ConvenienceTests.swift @@ -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(), diff --git a/Demo/Sources/Demos/Modern/PlacemarksDemo/Modern.PlacemarksDemo.Place.swift b/Demo/Sources/Demos/Modern/PlacemarksDemo/Modern.PlacemarksDemo.Place.swift index 7d07142..3054475 100644 --- a/Demo/Sources/Demos/Modern/PlacemarksDemo/Modern.PlacemarksDemo.Place.swift +++ b/Demo/Sources/Demos/Modern/PlacemarksDemo/Modern.PlacemarksDemo.Place.swift @@ -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 { diff --git a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.MainView.swift b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.MainView.swift index 8e35b18..1d8a2cf 100644 --- a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.MainView.swift +++ b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.MainView.swift @@ -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 diff --git a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.PokedexEntry.swift b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.PokedexEntry.swift index 8516c85..4ed9156 100644 --- a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.PokedexEntry.swift +++ b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.PokedexEntry.swift @@ -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 + typealias ImportSource = (index: Int, json: Dictionary) // 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"])) } } } diff --git a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.Service.swift b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.Service.swift index c8aa98e..c112a3f 100644 --- a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.Service.swift +++ b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.Service.swift @@ -128,7 +128,9 @@ extension Modern.PokedexDemo { _ = try transaction.importUniqueObjects( Into(), - sourceArray: results + sourceArray: results.enumerated().map { (index, json) in + (index: index, json: json) + } ) }, success: { result in diff --git a/Sources/CoreStoreSchema.swift b/Sources/CoreStoreSchema.swift index dda2d4a..5fa8c26 100644 --- a/Sources/CoreStoreSchema.swift +++ b/Sources/CoreStoreSchema.swift @@ -779,7 +779,7 @@ public final class CoreStoreSchema: DynamicSchema { ) } - _ = allFieldCoders + allFieldCoders .flatMap({ (_, values) in values }) .reduce( into: [:] as [NSValueTransformerName: Internals.AnyFieldCoder], diff --git a/Sources/DataStack+Migration.swift b/Sources/DataStack+Migration.swift index 1250cc3..68a797d 100644 --- a/Sources/DataStack+Migration.swift +++ b/Sources/DataStack+Migration.swift @@ -457,7 +457,7 @@ extension DataStack { DispatchQueue.main.async { - _ = withExtendedLifetime(childProgress) { (_: Progress) -> Void in } + withExtendedLifetime(childProgress) { (_: Progress) -> Void in } } } )