Adding new properties in vehicle model

This commit is contained in:
Selim Mustafaev 2022-03-29 18:17:15 +03:00
parent aa7efbe1b0
commit b81b613c9f
6 changed files with 76 additions and 15 deletions

View File

@ -20,6 +20,7 @@
6841AF924E165F1B3A3B5FB5 /* AuthController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6841ABEA0314E3B4E438C311 /* AuthController.swift */; };
7A1D80E027F1F275007BD64F /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7A1D80DF27F1F275007BD64F /* DifferenceKit */; };
7A1D80E627F20FCB007BD64F /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7A1D80E527F20FCB007BD64F /* DifferenceKit */; };
7A1D80E827F30399007BD64F /* VModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1D80E727F30399007BD64F /* VModel.swift */; };
7A24C19727EE212E00049E7F /* RoadNumbers.otf in Resources */ = {isa = PBXBuildFile; fileRef = 7A24C19527EE212E00049E7F /* RoadNumbers.otf */; };
7A24C19827EE212E00049E7F /* RoadNumbers2.0.otf in Resources */ = {isa = PBXBuildFile; fileRef = 7A24C19627EE212E00049E7F /* RoadNumbers2.0.otf */; };
7A24C19C27EE25B400049E7F /* PlateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A24C19A27EE25B400049E7F /* PlateView.swift */; };
@ -132,6 +133,7 @@
6841ADEEC165FA9124C5EF40 /* UITextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextField.swift; sourceTree = "<group>"; };
6841AFB465BF16E122875D9A /* ACButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ACButton.swift; sourceTree = "<group>"; };
6841AFE790F6FC06838B1E2C /* UIControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControl.swift; sourceTree = "<group>"; };
7A1D80E727F30399007BD64F /* VModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VModel.swift; sourceTree = "<group>"; };
7A24C19527EE212E00049E7F /* RoadNumbers.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = RoadNumbers.otf; sourceTree = "<group>"; };
7A24C19627EE212E00049E7F /* RoadNumbers2.0.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = RoadNumbers2.0.otf; sourceTree = "<group>"; };
7A24C19A27EE25B400049E7F /* PlateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlateView.swift; sourceTree = "<group>"; };
@ -421,6 +423,7 @@
7A49F50927D406CB00AEAAE0 /* Settings.swift */,
7A49F50A27D406CB00AEAAE0 /* PlateNumber.swift */,
7A49F50B27D406CB00AEAAE0 /* VName.swift */,
7A1D80E727F30399007BD64F /* VModel.swift */,
);
path = Models;
sourceTree = "<group>";
@ -726,6 +729,7 @@
7A49F50227D406C300AEAAE0 /* StorageService.swift in Sources */,
7A49F4FE27D406BA00AEAAE0 /* AnyEncodable.swift in Sources */,
7A49F51227D406CB00AEAAE0 /* VName.swift in Sources */,
7A1D80E827F30399007BD64F /* VModel.swift in Sources */,
7A49F51127D406CB00AEAAE0 /* PlateNumber.swift in Sources */,
7A49F50C27D406CB00AEAAE0 /* VBrand.swift in Sources */,
7A49F51027D406CB00AEAAE0 /* Settings.swift in Sources */,

View File

@ -6,20 +6,38 @@
<relationship name="vehicle" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Vehicle" inverseName="brand" inverseEntity="Vehicle"/>
</entity>
<entity name="Vehicle" representedClassName=".CDVehicle" syncable="YES" codeGenerationType="class">
<attribute name="addedBy" optional="YES" attributeType="String"/>
<attribute name="addedDate" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="category" optional="YES" attributeType="String"/>
<attribute name="color" optional="YES" attributeType="String"/>
<attribute name="currentNumber" optional="YES" attributeType="String"/>
<attribute name="isJapanese" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isRightWheel" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="number" optional="YES" attributeType="String"/>
<attribute name="pts" optional="YES" attributeType="String"/>
<attribute name="sts" optional="YES" attributeType="String"/>
<attribute name="synchronized" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="updatedDate" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="vin1" optional="YES" attributeType="String"/>
<attribute name="vin2" optional="YES" attributeType="String"/>
<attribute name="year" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<relationship name="brand" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VBrand" inverseName="vehicle" inverseEntity="VBrand"/>
<relationship name="model" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VModel" inverseName="vehicle" inverseEntity="VModel"/>
</entity>
<entity name="VModel" representedClassName=".CDVModel" syncable="YES" codeGenerationType="class">
<relationship name="name" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VName" inverseName="model" inverseEntity="VName"/>
<relationship name="vehicle" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Vehicle" inverseName="model" inverseEntity="Vehicle"/>
</entity>
<entity name="VName" representedClassName=".CDVName" 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"/>
<relationship name="model" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="VModel" inverseName="name" inverseEntity="VModel"/>
</entity>
<elements>
<element name="VBrand" positionX="118.7528686523438" positionY="-209.1094360351562" width="128" height="74"/>
<element name="Vehicle" positionX="-145.9427490234375" positionY="-363.4805297851562" width="128" height="104"/>
<element name="VName" positionX="-54" positionY="9" width="128" height="74"/>
<element name="Vehicle" positionX="-145.9427490234375" positionY="-363.4805297851562" width="128" height="284"/>
<element name="VName" positionX="-54" positionY="9" width="128" height="89"/>
<element name="VModel" positionX="-9" positionY="-207" width="128" height="59"/>
</elements>
</model>

View File

@ -9,14 +9,11 @@ public struct VBrand: Decodable {
extension CDVBrand {
convenience init(vbrand: VBrand, context: NSManagedObjectContext) {
convenience init(vbrand: VBrand?, context: NSManagedObjectContext) {
self.init(context: context)
self.logo = vbrand.logo
if let vname = vbrand.name {
self.name = CDVName(vname: vname, context: context)
}
self.logo = vbrand?.logo
self.name = CDVName(vname: vbrand?.name, context: context)
}
}

View File

@ -0,0 +1,22 @@
//
// VModel.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 29.03.2022.
//
import Foundation
import CoreData
public struct VModel: Decodable {
let name: VName?
}
extension CDVModel {
convenience init(model: VModel?, context: NSManagedObjectContext) {
self.init(context: context)
self.name = CDVName(vname: model?.name, context: context)
}
}

View File

@ -9,11 +9,11 @@ public struct VName: Decodable {
extension CDVName {
convenience init(vname: VName, context: NSManagedObjectContext) {
convenience init(vname: VName?, context: NSManagedObjectContext) {
self.init(context: context)
self.normalized = vname.normalized
self.original = vname.original
self.normalized = vname?.normalized
self.original = vname?.original
}
}

View File

@ -7,8 +7,19 @@ public struct Vehicle: Decodable {
public let number: String
public let currentNumber: String?
public let brand: VBrand?
public let model: VModel?
public let addedDate: TimeInterval
public let updatedDate: TimeInterval
public let color: String?
public let year: Int64?
public let category: String?
public let vin1: String?
public let vin2: String?
public let sts: String?
public let pts: String?
public let isRightWheel: Bool?
public let isJapanese: Bool?
public let addedBy: String?
}
extension CDVehicle: Dated {
@ -42,10 +53,19 @@ extension CDVehicle {
self.currentNumber = vehicle.currentNumber
self.addedDate = vehicle.addedDate/1000
self.updatedDate = vehicle.updatedDate/1000
if let vbrand = vehicle.brand {
self.brand = CDVBrand(vbrand: vbrand, context: context)
}
self.color = vehicle.color
self.brand = CDVBrand(vbrand: vehicle.brand, context: context)
self.model = CDVModel(model: vehicle.model, context: context)
self.year = vehicle.year ?? 0
self.category = category
self.vin1 = vehicle.vin1
self.vin2 = vehicle.vin2
self.sts = vehicle.sts
self.pts = vehicle.pts
self.isRightWheel = vehicle.isRightWheel ?? false
self.isJapanese = vehicle.isJapanese ?? false
self.addedBy = vehicle.addedBy
self.synchronized = true
}
public var unrecognized: Bool {