This repository was archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructor.swift
73 lines (55 loc) · 1.89 KB
/
Instructor.swift
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Instructor.swift
// social_project
//
// Created by Saeed Ali on 12/13/17.
// Copyright © 2017 Saeed Ali. All rights reserved.
//
import Foundation
public class Instructor {
public var first_name : String?
public var last_name : String?
public var id : Int?
/**
Returns an array of models based on given dictionary.
Sample usage:
let instructor_list = Instructor.modelsFromDictionaryArray(someDictionaryArrayFromJSON)
- parameter array: NSArray from JSON dictionary.
- returns: Array of Instructor Instances.
*/
public class func modelsFromDictionaryArray(array:NSArray) -> [Instructor]
{
var models:[Instructor] = []
for item in array
{
models.append(Instructor(dictionary: item as! NSDictionary)!)
}
return models
}
/**
Constructs the object based on the given dictionary.
Sample usage:
let instructor = Instructor(someDictionaryFromJSON)
- parameter dictionary: NSDictionary from JSON.
- returns: Instructor Instance.
*/
required public init?(dictionary: NSDictionary) {
first_name = dictionary["first_name"] as? String
last_name = dictionary["last_name"] as? String
id = Int((dictionary["id"] as? String)!)
}
/**
Returns the dictionary representation for the current instance.
- returns: NSDictionary.
*/
public func dictionaryRepresentation() -> NSDictionary {
let dictionary = NSMutableDictionary()
dictionary.setValue(self.first_name, forKey: "first_name")
dictionary.setValue(self.last_name, forKey: "last_name")
dictionary.setValue(self.id, forKey: "id")
return dictionary
}
public func fullName()-> String {
return first_name! + " " + last_name!
}
}