-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITableViewControllerExtensions.swift
99 lines (80 loc) · 2.99 KB
/
UITableViewControllerExtensions.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import Foundation
import UIKit
struct TableItem {
let title: String
let price: Float
let creationDate: NSDate
init(name:String, price:Float){
self.title = name
self.price = price
self.creationDate = NSDate()
}
private func convertDateFormatter(date: String) -> String
{
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
dateFormatter.timeZone = NSTimeZone(name: "UTC")
let date = dateFormatter.dateFromString(date)
dateFormatter.dateFormat = "yyyy MMM EEEE HH:mm"///this is what you want to convert format
dateFormatter.timeZone = NSTimeZone(name: "UTC")
let timeStamp = dateFormatter.stringFromDate(date!)
return timeStamp
}
public init(dictionary: Dictionary<String, AnyObject>){
self.title = (dictionary["title"] as? String)!
self.price = (dictionary["price"] as? Float)!
self.creationDate = (dictionary["creationDate"] as? NSDate)!
}
// Encode
public func encode() -> Dictionary<String, AnyObject> {
var dictionary : Dictionary = Dictionary<String, AnyObject>()
dictionary["title"] = self.title
dictionary["price"] = self.price
dictionary["creationDate"] = self.creationDate
print(dictionary)
return dictionary
}
}
struct TableSection {
let name: String
var TableItems: Dictionary<Int,TableItem>
let creationDate: NSDate
init(name:String, items:[Int:TableItem]?){
self.name = name
TableItems = items!
creationDate = NSDate()
}
init(name:String){
self.name = name
creationDate = NSDate()
self.TableItems = [:]
}
mutating func addItem(item:TableItem){
self.TableItems[self.TableItems.count] = item
}
mutating func addItem(name:String, price:Float){
self.TableItems[self.TableItems.count] = TableItem(name: name, price: price)
}
public init(dictionary: Dictionary<String, AnyObject>){
self.name = (dictionary["name"] as? String)!
var en = dictionary["TableItems"] as? NSDictionary
self.TableItems = [:]
for (name, value) in en! {
var dictio = value as? Dictionary<String,AnyObject>
self.TableItems[TableItems.count] = TableItem(dictionary: dictio!)
}
self.creationDate = (dictionary["creationDate"] as? NSDate)!
}
// Encode
public func encode() -> Dictionary<String, AnyObject> {
var dictionary : Dictionary = Dictionary<String, AnyObject>()
dictionary["name"] = self.name
dictionary["creationDate"] = self.creationDate
var exp = Dictionary<Int,Dictionary<String, AnyObject>>()
for (id, object) in TableItems {
exp[id] = object.encode()
}
dictionary["TableItems"] = exp
return dictionary
}
}