First version
This commit is contained in:
14
CHDataManagement/Extensions/Binding+Extension.swift
Normal file
14
CHDataManagement/Extensions/Binding+Extension.swift
Normal file
@ -0,0 +1,14 @@
|
||||
import SwiftUI
|
||||
|
||||
public extension Binding where Value: Equatable, Value: Sendable {
|
||||
|
||||
init(_ source: Binding<Value?>, replacingNilWith nilProxy: Value) {
|
||||
self.init(
|
||||
get: { source.wrappedValue ?? nilProxy },
|
||||
set: { newValue in
|
||||
if newValue == nilProxy { source.wrappedValue = nil }
|
||||
else { source.wrappedValue = newValue }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
15
CHDataManagement/Extensions/Color+RGB.swift
Normal file
15
CHDataManagement/Extensions/Color+RGB.swift
Normal file
@ -0,0 +1,15 @@
|
||||
import SwiftUI
|
||||
|
||||
extension Color {
|
||||
|
||||
init(_ r: Int, _ g: Int, _ b: Int) {
|
||||
self.init(r: r, g: g, b: b)
|
||||
}
|
||||
|
||||
init(r: Int, g: Int, b: Int) {
|
||||
self.init(
|
||||
red: Double(r) / 255,
|
||||
green: Double(g) / 255,
|
||||
blue: Double(b) / 255)
|
||||
}
|
||||
}
|
15
CHDataManagement/Extensions/Environment+Language.swift
Normal file
15
CHDataManagement/Extensions/Environment+Language.swift
Normal file
@ -0,0 +1,15 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct LanguageKey: EnvironmentKey {
|
||||
|
||||
static let defaultValue: ContentLanguage = .english
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
|
||||
var language: ContentLanguage {
|
||||
get { self[LanguageKey.self] }
|
||||
set { self[LanguageKey.self] = newValue }
|
||||
}
|
||||
}
|
11
CHDataManagement/Extensions/String+Extensions.swift
Normal file
11
CHDataManagement/Extensions/String+Extensions.swift
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
extension String {
|
||||
|
||||
func htmlEscaped() -> String {
|
||||
replacingOccurrences(of: "&", with: "&")
|
||||
.replacingOccurrences(of: "\"", with: """)
|
||||
.replacingOccurrences(of: "'", with: "'")
|
||||
.replacingOccurrences(of: "<", with: "<")
|
||||
.replacingOccurrences(of: ">", with: ">")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user