-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNSNumber+Extension.swift
55 lines (48 loc) · 950 Bytes
/
NSNumber+Extension.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
//
// Int+Extension.swift
// Shoaib
//
// Created by Shoaib Sarwar Cheema on 07/04/2016.
// Copyright © 2016. All rights reserved.
//
import Foundation
extension NSNumber {
func format(_ f: String) -> String {
return String(format: "%\(f)f", self)
}
}
extension Int {
func boolValue() ->Bool {
switch self {
case 0:
return false
default:
return true
}
}
}
extension Bool {
func intValue() ->Int {
switch self {
case false:
return 0
default:
return 1
}
}
}
extension Int {
func format(_ f: String) -> String {
return String(format: "%\(f)d", self)
}
}
extension Float {
func format(_ f: String) -> String {
return String(format: "%\(f)f", self)
}
}
extension Double {
func format(_ f: String) -> String {
return String(format: "%\(f)f", self)
}
}