d
This commit is contained in:
15
mod/CordX/CordX.podspec
Normal file
15
mod/CordX/CordX.podspec
Normal file
@@ -0,0 +1,15 @@
|
||||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = 'CordX'
|
||||
s.version = '2023.12.28'
|
||||
s.license = 'IVCS'
|
||||
s.summary = 'Упрощённое общение с шиной из SwiftUI'
|
||||
s.homepage = 'IVCS'
|
||||
s.author = 'IVCS'
|
||||
s.source = { :git => 'https://fake.com/FAKE.git', :tag => s.version }
|
||||
s.source_files = 'src/**/*.swift'
|
||||
s.swift_version = '5.2'
|
||||
s.ios.deployment_target = '14.0'
|
||||
s.dependency 'BusX'
|
||||
|
||||
end
|
||||
17
mod/CordX/src/Cord.Button.swift
Normal file
17
mod/CordX/src/Cord.Button.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import BusX
|
||||
import Combine
|
||||
|
||||
extension Cord {
|
||||
public final class Button: ObservableObject {
|
||||
public let press = PassthroughSubject<Void, Never>()
|
||||
var subscriptions = [AnyCancellable]()
|
||||
|
||||
public init(_ key: String) {
|
||||
Bus.send(
|
||||
key,
|
||||
press.eraseToAnyPublisher(),
|
||||
sub: &subscriptions
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
9
mod/CordX/src/Cord.Onlys.swift
Normal file
9
mod/CordX/src/Cord.Onlys.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
extension Cord {
|
||||
/// Пропускаем лишь значения от UI
|
||||
///
|
||||
/// - Returns: Значение без префиксов "a:"/"u:"
|
||||
static func onlyUIText(_ s: String) -> String? {
|
||||
guard s.hasPrefix("u:") else { return nil }
|
||||
return String(s.dropFirst(2))
|
||||
}
|
||||
}
|
||||
21
mod/CordX/src/Cord.Receive.swift
Normal file
21
mod/CordX/src/Cord.Receive.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
import BusX
|
||||
import Combine
|
||||
|
||||
extension Cord {
|
||||
public final class Receive<T>: ObservableObject {
|
||||
@Published public var value: T
|
||||
var subscriptions = [AnyCancellable]()
|
||||
|
||||
public init(
|
||||
_ key: String,
|
||||
_ defaultValue: T
|
||||
) {
|
||||
value = defaultValue
|
||||
Bus.receive(
|
||||
[key],
|
||||
{ [weak self] (_, v: T) in self?.value = v },
|
||||
sub: &subscriptions
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
30
mod/CordX/src/Cord.TextField.swift
Normal file
30
mod/CordX/src/Cord.TextField.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
import BusX
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
extension Cord {
|
||||
public final class TextField: ObservableObject {
|
||||
@Published public var value = "a:"
|
||||
var subscriptions = [AnyCancellable]()
|
||||
|
||||
public init(
|
||||
_ textApp: String,
|
||||
_ textUI: String
|
||||
) {
|
||||
Bus.send(
|
||||
textUI,
|
||||
$value
|
||||
.removeDuplicates()
|
||||
.compactMap(onlyUIText)
|
||||
.eraseToAnyPublisher(),
|
||||
sub: &subscriptions
|
||||
)
|
||||
|
||||
Bus.receive(
|
||||
[textApp],
|
||||
{ [weak self] (_, v: String) in self?.value = "a:\(v)" },
|
||||
sub: &subscriptions
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
19
mod/CordX/src/Cord.TextFieldValueOwner.swift
Normal file
19
mod/CordX/src/Cord.TextFieldValueOwner.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
|
||||
extension Cord {
|
||||
public final class TextFieldValueOwner: Formatter {
|
||||
public override func string(for obj: Any?) -> String? {
|
||||
guard let str = obj as? String else { return nil }
|
||||
return String(str.dropFirst(2))
|
||||
}
|
||||
|
||||
public override func getObjectValue(
|
||||
_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?,
|
||||
for string: String,
|
||||
errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?
|
||||
) -> Bool {
|
||||
obj?.pointee = "u:\(string)" as AnyObject
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
1
mod/CordX/src/Cord.swift
Normal file
1
mod/CordX/src/Cord.swift
Normal file
@@ -0,0 +1 @@
|
||||
public enum Cord { }
|
||||
Reference in New Issue
Block a user