Skip to content

Commit 0148d12

Browse files
committed
Added more extensions.
1 parent 4f47dcb commit 0148d12

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if canImport(CoreGraphics)
2+
import CoreGraphics
3+
4+
extension CGFloat {
5+
6+
public func rounded(to places: Int) -> CGFloat {
7+
let divisor = pow(10.0, CGFloat(places))
8+
return (self * divisor).rounded() / divisor
9+
}
10+
}
11+
#endif

Sources/SwiftBoost/Foundation/Extensions/ArrayExtension.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ public extension Array where Element: Equatable {
4949
return result
5050
}
5151
}
52+
53+
public extension ArraySlice {
54+
55+
var array: [Element] {
56+
return Array(self)
57+
}
58+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import Foundation
22

3-
public extension NotificationCenter {
3+
extension NotificationCenter {
44

5-
func post(name: NSNotification.Name) {
5+
public func addObserver(_ names: NSNotification.Name..., using block: @escaping @Sendable (Notification) -> Void) {
6+
for name in names {
7+
NotificationCenter.default.addObserver(forName: name, object: nil, queue: nil, using: block)
8+
}
9+
}
10+
11+
public func post(name: NSNotification.Name) {
612
post(name: name, object: nil)
713
}
814
}

0 commit comments

Comments
 (0)