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 pathUser.swift
78 lines (56 loc) · 1.87 KB
/
User.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
74
75
76
77
78
//
// User.swift
// social_project
//
// Created by Saeed Ali on 12/28/17.
// Copyright © 2017 Saeed Ali. All rights reserved.
//
import Foundation
import Foundation
public class User {
public var data : Profile?
public var id : Int?
public var type : String?
/**
Returns an array of models based on given dictionary.
Sample usage:
let user_list = User.modelsFromDictionaryArray(someDictionaryArrayFromJSON)
- parameter array: NSArray from JSON dictionary.
- returns: Array of User Instances.
*/
public class func modelsFromDictionaryArray(array:NSArray) -> [User]
{
var models:[User] = []
for item in array
{
models.append(User(dictionary: item as! NSDictionary)!)
}
return models
}
/**
Constructs the object based on the given dictionary.
Sample usage:
let user = User(someDictionaryFromJSON)
- parameter dictionary: NSDictionary from JSON.
- returns: User Instance.
*/
required public init?(dictionary: NSDictionary) {
//if (dictionary["user"] != nil) {
if (dictionary["data"] != nil) {
data = Profile(dictionary: dictionary["data"] as! NSDictionary)
}
id = Int((dictionary["id"] as? String)!)
type = dictionary["type"] as? String
}
/**
Returns the dictionary representation for the current instance.
- returns: NSDictionary.
*/
public func dictionaryRepresentation() -> NSDictionary {
let dictionary = NSMutableDictionary()
dictionary.setValue(self.data?.dictionaryRepresentation(), forKey: "profile")
dictionary.setValue(self.id, forKey: "id")
dictionary.setValue(self.type, forKey: "type")
return dictionary
}
}