This repository has been 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
/
Likes.swift
73 lines (55 loc) · 1.89 KB
/
Likes.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
//
// Likes.swift
// social_project
//
// Created by Saeed Ali on 12/31/17.
// Copyright © 2017 Saeed Ali. All rights reserved.
//
import Foundation
public class Likes {
public var id : Int?
public var post_id : Int?
public var user_id : Int?
public var created_at : String?
/**
Returns an array of models based on given dictionary.
Sample usage:
let likes_list = Likes.modelsFromDictionaryArray(someDictionaryArrayFromJSON)
- parameter array: NSArray from JSON dictionary.
- returns: Array of Likes Instances.
*/
public class func modelsFromDictionaryArray(array:NSArray) -> [Likes]
{
var models:[Likes] = []
for item in array
{
models.append(Likes(dictionary: item as! [String: Any])!)
}
return models
}
/**
Constructs the object based on the given dictionary.
Sample usage:
let likes = Likes(someDictionaryFromJSON)
- parameter dictionary: NSDictionary from JSON.
- returns: Likes Instance.
*/
required public init?(dictionary: [String:Any]) {
id = Int((dictionary["id"] as? String)!)
post_id = Int((dictionary["post_id"] as? String)!)
user_id = Int((dictionary["user_id"] as? String)!)
created_at = dictionary["created_at"] as? String
}
/**
Returns the dictionary representation for the current instance.
- returns: NSDictionary.
*/
public func dictionaryRepresentation() -> NSDictionary {
let dictionary = NSMutableDictionary()
dictionary.setValue(self.id, forKey: "id")
dictionary.setValue(self.post_id, forKey: "post_id")
dictionary.setValue(self.user_id, forKey: "user_id")
dictionary.setValue(self.created_at, forKey: "created_at")
return dictionary
}
}