-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFoundation+PatchDay.swift
53 lines (42 loc) · 1.25 KB
/
Foundation+PatchDay.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
//
// ArrayExtension.swift
// PDKit
//
// Created by Juliya Smith on 10/29/19.
import Foundation
public extension Array {
func tryGet(at index: Index) -> Element? {
guard index < count && index >= 0 else { return nil }
return self[index]
}
}
public extension Array where Element: Equatable {
func tryGetIndex(item: Element?) -> Index? {
guard let item = item else { return nil }
return firstIndex(of: item)
}
}
// https://stackoverflow.com/questions/39677330/how-does-string-substring-work-in-swift
public extension String {
func index(from: Int) -> Index {
self.index(startIndex, offsetBy: from)
}
func substring(from: Int) -> String {
let fromIndex = index(from: from)
return String(self[fromIndex...])
}
func substring(to: Int) -> String {
let toIndex = index(from: to)
return String(self[..<toIndex])
}
func substring(with r: Range<Int>) -> String {
let startIndex = index(from: r.lowerBound)
let endIndex = index(from: r.upperBound)
return String(self[startIndex..<endIndex])
}
}
public extension UIViewController {
func getStyle() -> UIUserInterfaceStyle {
self.traitCollection.userInterfaceStyle
}
}