mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-23 01:44:06 -06:00
## Summary Swift lint and swiftformat are outdated. This PR does update those + applies the new formatting form swiftformat. There is 1 swift file with a manual change: `Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift`. This is done because `swiftlint` did create the following swiftlint error: `error: Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)`. Because it does change a lot of files the question is if we want to finetune the `swiftformat` rules. ## Screenshots No user facing changes. ## Link to pull request in Documentation repository NA ## Any other notes NA
31 lines
1023 B
Swift
31 lines
1023 B
Swift
import Foundation
|
|
import PromiseKit
|
|
import RealmSwift
|
|
|
|
public struct ClientEventStore {
|
|
public var addEvent: (ClientEvent) -> Promise<Void> = { event in
|
|
let realm = Current.realm()
|
|
Current.Log.info("\(event.type): \(event.text) \(event.jsonPayload ?? [:])")
|
|
return realm.reentrantWrite {
|
|
realm.add(event)
|
|
}
|
|
}
|
|
|
|
public func getEvents(filter: String? = nil) -> AnyRealmCollection<ClientEvent> {
|
|
let realm = Current.realm()
|
|
let objects = realm.objects(ClientEvent.self).sorted(byKeyPath: "date", ascending: false)
|
|
if let filter, filter.isEmpty == false {
|
|
return AnyRealmCollection(objects.filter(NSPredicate(format: "text contains[c] %@", filter)))
|
|
} else {
|
|
return AnyRealmCollection(objects)
|
|
}
|
|
}
|
|
|
|
public var clearAllEvents: () -> Promise<Void> = {
|
|
let realm = Current.realm()
|
|
return realm.reentrantWrite {
|
|
realm.delete(realm.objects(ClientEvent.self))
|
|
}
|
|
}
|
|
}
|