add models
This commit is contained in:
parent
96ee51f006
commit
8ddab46918
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
AutoCat2.xcodeproj/xcuserdata/
|
||||||
|
.DS_Store
|
||||||
@ -7,12 +7,12 @@
|
|||||||
<key>AutoCat2 (iOS).xcscheme_^#shared#^_</key>
|
<key>AutoCat2 (iOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>AutoCat2 (macOS).xcscheme_^#shared#^_</key>
|
<key>AutoCat2 (macOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>AutoCatCore.xcscheme_^#shared#^_</key>
|
<key>AutoCatCore.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19178.1" systemVersion="20F71" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19186" systemVersion="21A5294g" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
||||||
|
<entity name="VBrand" representedClassName="VBrand" syncable="YES" codeGenerationType="class">
|
||||||
|
<attribute name="logo" optional="YES" attributeType="String"/>
|
||||||
|
<relationship name="name" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VName" inverseName="brand" inverseEntity="VName"/>
|
||||||
|
<relationship name="vehicle" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Vehicle" inverseName="brand" inverseEntity="Vehicle"/>
|
||||||
|
</entity>
|
||||||
<entity name="Vehicle" representedClassName="Vehicle" syncable="YES" codeGenerationType="class">
|
<entity name="Vehicle" representedClassName="Vehicle" syncable="YES" codeGenerationType="class">
|
||||||
|
<attribute name="currentNumber" optional="YES" attributeType="String"/>
|
||||||
<attribute name="number" optional="YES" attributeType="String"/>
|
<attribute name="number" optional="YES" attributeType="String"/>
|
||||||
|
<relationship name="brand" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VBrand" inverseName="vehicle" inverseEntity="VBrand"/>
|
||||||
|
</entity>
|
||||||
|
<entity name="VName" representedClassName="VName" syncable="YES" codeGenerationType="class">
|
||||||
|
<attribute name="normalized" optional="YES" attributeType="String"/>
|
||||||
|
<attribute name="original" optional="YES" attributeType="String"/>
|
||||||
|
<relationship name="brand" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VBrand" inverseName="name" inverseEntity="VBrand"/>
|
||||||
</entity>
|
</entity>
|
||||||
<elements>
|
<elements>
|
||||||
<element name="Vehicle" positionX="-54" positionY="-9" width="128" height="44"/>
|
<element name="Vehicle" positionX="-145.9427490234375" positionY="-363.4805297851562" width="128" height="88"/>
|
||||||
|
<element name="VName" positionX="-54" positionY="9" width="128" height="88"/>
|
||||||
|
<element name="VBrand" positionX="118.7528686523438" positionY="-209.1094360351562" width="128" height="88"/>
|
||||||
</elements>
|
</elements>
|
||||||
</model>
|
</model>
|
||||||
@ -1,7 +1,16 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
@objc(Vehicle)
|
extension Vehicle {
|
||||||
public class Vehicle: NSManagedObject {
|
public var unrecognized: Bool {
|
||||||
@NSManaged public var number: String?
|
return self.brand == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
public var outdated: Bool {
|
||||||
|
if let current = self.currentNumber {
|
||||||
|
return current != self.number
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,10 +13,10 @@ struct PersistenceController {
|
|||||||
static var preview: PersistenceController = {
|
static var preview: PersistenceController = {
|
||||||
let result = PersistenceController(inMemory: true)
|
let result = PersistenceController(inMemory: true)
|
||||||
let viewContext = result.container.viewContext
|
let viewContext = result.container.viewContext
|
||||||
for _ in 0..<10 {
|
// for _ in 0..<10 {
|
||||||
let newItem = Item(context: viewContext)
|
// let newItem = Item(context: viewContext)
|
||||||
newItem.timestamp = Date()
|
// newItem.timestamp = Date()
|
||||||
}
|
// }
|
||||||
do {
|
do {
|
||||||
try viewContext.save()
|
try viewContext.save()
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@ -2,16 +2,27 @@ import SwiftUI
|
|||||||
|
|
||||||
struct CheckView: View {
|
struct CheckView: View {
|
||||||
@State private var number: String = ""
|
@State private var number: String = ""
|
||||||
|
@FetchRequest(entity: Vehicle.entity(), sortDescriptors: []) var vehicles: FetchedResults<Vehicle>
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
NavigationView {
|
||||||
VStack(alignment: .center, spacing: 16) {
|
VStack(alignment: .center, spacing: 16) {
|
||||||
TextField("", text: $number)
|
TextField("A123AA777", text: $number)
|
||||||
Button("Check") {
|
Button("Check") {
|
||||||
|
|
||||||
}
|
}
|
||||||
// List(["one", "two", "three"]) { item in
|
List(vehicles) { vehicle in
|
||||||
// Text(item)
|
Text(vehicle.number ?? "<none>")
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .primaryAction) {
|
||||||
|
Button("New") {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if os(iOS)
|
||||||
|
.navigationBarTitle("Title", displayMode: .inline)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,5 +30,6 @@ struct CheckView: View {
|
|||||||
struct CheckView_Previews: PreviewProvider {
|
struct CheckView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CheckView()
|
CheckView()
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,64 @@ import SwiftUI
|
|||||||
|
|
||||||
struct MainViewBig: View {
|
struct MainViewBig: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("Main view big")
|
NavigationView {
|
||||||
|
SidebarView()
|
||||||
|
Text("Master")
|
||||||
|
Text("Detail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SidebarView: View {
|
||||||
|
@State var selection: String?
|
||||||
|
|
||||||
|
@FetchRequest(entity: Vehicle.entity(), sortDescriptors: []) var vehicles: FetchedResults<Vehicle>
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List(selection: $selection) {
|
||||||
|
Section("History") {
|
||||||
|
NavigationLink(destination: VehiclesListView()) {
|
||||||
|
Label("All", systemImage: "car.2")
|
||||||
|
.badge(vehicles.count)
|
||||||
|
}
|
||||||
|
NavigationLink(destination: VehiclesListView()) {
|
||||||
|
Label("Unreconized", systemImage: "eye.slash")
|
||||||
|
.badge(vehicles.filter(\.unrecognized).count)
|
||||||
|
}
|
||||||
|
NavigationLink(destination: VehiclesListView()) {
|
||||||
|
Label("Outdated", systemImage: "wind")
|
||||||
|
.badge(vehicles.filter(\.outdated).count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.collapsible(false)
|
||||||
|
|
||||||
|
Section("Other") {
|
||||||
|
Label("Recordings", systemImage: "waveform.path")
|
||||||
|
Label("Search", systemImage: "magnifyingglass")
|
||||||
|
}
|
||||||
|
.collapsible(false)
|
||||||
|
}
|
||||||
|
.frame(minWidth: 180)
|
||||||
|
// .toolbar {
|
||||||
|
// ToolbarItem(placement: .primaryAction) {
|
||||||
|
// Button("xxx") {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VehiclesListView: View {
|
||||||
|
var body: some View {
|
||||||
|
Text("Vehicles list")
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .primaryAction) {
|
||||||
|
Button("xxx") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,9 @@ struct MainViewSmall: View {
|
|||||||
Text("Settings")
|
Text("Settings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if os(iOS)
|
||||||
|
.navigationBarHidden(true)
|
||||||
|
#endif
|
||||||
Text("detail")
|
Text("detail")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user