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 self.prepareStack { (stack) in
_ = withExtendedLifetime(stack.beginUnsafe()) { (transaction: UnsafeDataTransaction) in withExtendedLifetime(stack.beginUnsafe()) { (transaction: UnsafeDataTransaction) in
let controller = transaction.createFetchedResultsController( let controller = transaction.createFetchedResultsController(
From<TestEntity1>(), From<TestEntity1>(),

View File

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

View File

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

View File

@@ -13,9 +13,12 @@ extension Modern.PokedexDemo {
final class PokedexEntry: CoreStoreObject, ImportableUniqueObject { final class PokedexEntry: CoreStoreObject, ImportableUniqueObject {
// MARK: Internal // MARK: Internal
@Field.Stored("id") @Field.Stored("id")
var id: String = "" var id: Int = 0
@Field.Stored("name")
var name: String = ""
@Field.Stored("url") @Field.Stored("url")
var url: URL! var url: URL!
@@ -27,14 +30,16 @@ extension Modern.PokedexDemo {
// MARK: ImportableObject // MARK: ImportableObject
typealias ImportSource = Dictionary<String, Any> typealias ImportSource = (index: Int, json: Dictionary<String, Any>)
// MARK: ImportableUniqueObject // MARK: ImportableUniqueObject
typealias UniqueIDType = Int
static let uniqueIDKeyPath: String = String(keyPath: \Modern.PokedexDemo.PokedexEntry.$id) static let uniqueIDKeyPath: String = String(keyPath: \Modern.PokedexDemo.PokedexEntry.$id)
var uniqueIDValue: String { var uniqueIDValue: UniqueIDType {
get { 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 { 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( _ = try transaction.importUniqueObjects(
Into<Modern.PokedexDemo.PokedexEntry>(), Into<Modern.PokedexDemo.PokedexEntry>(),
sourceArray: results sourceArray: results.enumerated().map { (index, json) in
(index: index, json: json)
}
) )
}, },
success: { result in success: { result in

View File

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

View File

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