-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee+CoreDataClass.swift
More file actions
39 lines (28 loc) · 1.11 KB
/
Employee+CoreDataClass.swift
File metadata and controls
39 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Employee+CoreDataClass.swift
// Timeclock
//
// Created by Tom Hutchinson on 22/10/2016.
// Copyright © 2016 Kairos. All rights reserved.
//
import Foundation
import CoreData
open class Employee: NSManagedObject, ManagedObjectType {
static let EntityName = "Employee"
enum Attributes: String {
case badgeNumber = "BADGE_NUMBER"
case firstName = "FIRST_NAME"
}
//MARK: Convenience
class func insertNewInContext(_ managedObjectContext: NSManagedObjectContext) -> Employee? {
return NSEntityDescription.insertNewObject(forEntityName: Employee.EntityName, into: managedObjectContext) as? Employee
}
class func fromJSON(_ json: JSONType, inContext context: NSManagedObjectContext) -> Employee {
let employee: Employee = context.insertObject()
if let badgeNumber = json[Employee.Attributes.badgeNumber.rawValue] as? NSNumber {
employee.badgeNumber = badgeNumber.stringValue
}
employee.firstName = json[Employee.Attributes.firstName.rawValue] as? String
return employee
}
}