-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSDictionary+Utility.swift
54 lines (45 loc) · 1.07 KB
/
NSDictionary+Utility.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
//
// NSDictionary+Utility.swift
//
//
// Created by subhajit halder on 21/02/17.
// Copyright © 2017 SubhajitHalder. All rights reserved.
//
import Foundation
extension NSDictionary {
func toStringFrom(key akey: String) -> String {
if let str = self[akey] as? String {
return str
} else {
return ""
}
}
func toNSArrayFrom(key aKey: String) -> NSArray {
if let arr = self[aKey] as? NSArray {
return arr
} else {
return []
}
}
func toIntFrom(key akey: String) -> Int {
if let int = self[akey] as? Int {
return int
} else {
return 0
}
}
func toFloatFrom(key akey: String) -> Float {
if let float = self[akey] as? Float {
return float
} else {
return 0.0
}
}
func toBoolFrom(key akey: String) -> Bool {
if let bool = self[akey] as? Bool {
return bool
} else {
return false
}
}
}