Skip to content

Instantly share code, notes, and snippets.

View klein-artur's full-sized avatar

Artur Hellmann klein-artur

View GitHub Profile
@klein-artur
klein-artur / GeneralAlert.swift
Created January 10, 2023 23:00
An alert modifier for better alert handling in SwiftUI
struct AlertAction {
let title: String
var role: ButtonRole? = .none
let action: (() -> Void)
}
struct AlertItem {
let title: String
let message: String
let actions: [AlertAction]
@klein-artur
klein-artur / testableSwiftResult.swift
Created January 19, 2023 00:42
Checking Result for success or error in Tests
extension Result where Failure == ParseError {
func checkError(messageIfNotError: String, type: ParseErrorType) {
switch self {
case .success(_):
XCTFail(messageIfNotError)
case let .failure(error):
if error.type != type {
XCTFail("Should have thrown \(type.rawValue) but did \(error.type)")
}
}
@klein-artur
klein-artur / Selectables.swift
Created July 8, 2023 00:13
SwiftUI Selectable List
struct Selectables<Data, ID: Hashable, Content>: View where Content: View {
let data: [Data]
@Binding var selectedIds: [ID]
let id: KeyPath<Data, ID>
let content: (Data, Binding<Bool>) -> Content
init(_ data: [Data], selectedIds: Binding<[ID]>, id: KeyPath<Data, ID>, @ViewBuilder content: @escaping (Data, Binding<Bool>) -> Content) {
self.data = data
self._selectedIds = selectedIds
self.id = id