Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
920 B
1
Indexable
Never
//
//  Item.CoreDataAdapters.swift
//  ShoppingList
//
//  Created by Marco on 14/03/24.
//

import Foundation

/// CoreData managed objects <=> App entities adapters
extension Model.Entity.Items.Item: ForeignModelAdapter {
  func adaptExistingForeignModel(_ model: inout Item) {
    model.title = self.title
    model.notes = self.notes
    model.price = self.price
    model.priority = self.priority
    model.completed = self.completed
    model.timestamp = self.dateAdded
  }

  static func newEntity(from coreDataModel: Item) -> Model.Entity.Items.Item {
    return .init(id: coreDataModel.id?.uuidString ?? "",
                 title: coreDataModel.title ?? "",
                 notes: coreDataModel.notes,
                 priority: coreDataModel.priority,
                 price: coreDataModel.price,
                 completed: coreDataModel.completed,
                 dateAdded: coreDataModel.timestamp)
  }
}
Leave a Comment