@@ -4,6 +4,7 @@ platform :ios, '14.0' | |||||
# Source. | # Source. | ||||
pod 'BusX', :path => '../mod/BusX' | pod 'BusX', :path => '../mod/BusX' | ||||
pod 'CordX', :path => '../mod/CordX' | |||||
target 'pesochnicza' do | target 'pesochnicza' do | ||||
use_frameworks! | use_frameworks! | ||||
@@ -1,16 +1,22 @@ | |||||
PODS: | PODS: | ||||
- BusX (2023.12.28) | - BusX (2023.12.28) | ||||
- CordX (2023.12.28): | |||||
- BusX | |||||
DEPENDENCIES: | DEPENDENCIES: | ||||
- BusX (from `../mod/BusX`) | - BusX (from `../mod/BusX`) | ||||
- CordX (from `../mod/CordX`) | |||||
EXTERNAL SOURCES: | EXTERNAL SOURCES: | ||||
BusX: | BusX: | ||||
:path: "../mod/BusX" | :path: "../mod/BusX" | ||||
CordX: | |||||
:path: "../mod/CordX" | |||||
SPEC CHECKSUMS: | SPEC CHECKSUMS: | ||||
BusX: fd22c04ad544d131e66315c1a33d87d85b19712e | BusX: fd22c04ad544d131e66315c1a33d87d85b19712e | ||||
CordX: 63515d366b217366b9562edcfef34630a7be1171 | |||||
PODFILE CHECKSUM: c4bbd7cc826ceee472b0bbb53eb2d5dc7dd1f97e | |||||
PODFILE CHECKSUM: 1091fc5c43b2a3881ee63b88848d7ed4f2ede026 | |||||
COCOAPODS: 1.13.0 | COCOAPODS: 1.13.0 |
@@ -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 |
@@ -2,11 +2,11 @@ import BusX | |||||
import Combine | import Combine | ||||
extension Cord { | extension Cord { | ||||
final class Button: ObservableObject { | |||||
let press = PassthroughSubject<Void, Never>() | |||||
public final class Button: ObservableObject { | |||||
public let press = PassthroughSubject<Void, Never>() | |||||
var subscriptions = [AnyCancellable]() | var subscriptions = [AnyCancellable]() | ||||
init(_ key: String) { | |||||
public init(_ key: String) { | |||||
Bus.send( | Bus.send( | ||||
key, | key, | ||||
press.eraseToAnyPublisher(), | press.eraseToAnyPublisher(), |
@@ -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)) | |||||
} | |||||
} |
@@ -2,11 +2,11 @@ import BusX | |||||
import Combine | import Combine | ||||
extension Cord { | extension Cord { | ||||
final class Receive<T>: ObservableObject { | |||||
@Published var value: T | |||||
public final class Receive<T>: ObservableObject { | |||||
@Published public var value: T | |||||
var subscriptions = [AnyCancellable]() | var subscriptions = [AnyCancellable]() | ||||
init( | |||||
public init( | |||||
_ key: String, | _ key: String, | ||||
_ defaultValue: T | _ defaultValue: T | ||||
) { | ) { |
@@ -3,17 +3,20 @@ import Combine | |||||
import SwiftUI | import SwiftUI | ||||
extension Cord { | extension Cord { | ||||
final class TextField: ObservableObject { | |||||
@Published var value = "a:" | |||||
public final class TextField: ObservableObject { | |||||
@Published public var value = "a:" | |||||
var subscriptions = [AnyCancellable]() | var subscriptions = [AnyCancellable]() | ||||
init( | |||||
public init( | |||||
_ textApp: String, | _ textApp: String, | ||||
_ textUI: String | _ textUI: String | ||||
) { | ) { | ||||
Bus.send( | Bus.send( | ||||
textUI, | textUI, | ||||
$value.removeDuplicates().compactMap(onlyUIText).eraseToAnyPublisher(), | |||||
$value | |||||
.removeDuplicates() | |||||
.compactMap(onlyUIText) | |||||
.eraseToAnyPublisher(), | |||||
sub: &subscriptions | sub: &subscriptions | ||||
) | ) | ||||
@@ -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,2 +1 @@ | |||||
public enum Cord { } | public enum Cord { } |
@@ -1,8 +0,0 @@ | |||||
/// Пропускаем лишь значения от UI | |||||
/// | |||||
/// - Returns: Значение без префиксов "a:"/"u:" | |||||
func onlyUIText(_ s: String) -> String? { | |||||
guard s.hasPrefix("u:") else { return nil } | |||||
return String(s.dropFirst(2)) | |||||
} |
@@ -29,6 +29,14 @@ enum MeetupId { | |||||
} | } | ||||
return r | return r | ||||
} | } | ||||
/// Пропускаем лишь значения от UI | |||||
/// | |||||
/// - Returns: Значение без префиксов "a:"/"u:" | |||||
func onlyUIText(_ s: String) -> String? { | |||||
guard s.hasPrefix("u:") else { return nil } | |||||
return String(s.dropFirst(2)) | |||||
} | |||||
} | } | ||||
@@ -1,17 +0,0 @@ | |||||
import Foundation | |||||
class TextFieldValueOwner: Formatter { | |||||
override func string(for obj: Any?) -> String? { | |||||
guard let str = obj as? String else { return nil } | |||||
return String(str.dropFirst(2)) | |||||
} | |||||
override func getObjectValue( | |||||
_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, | |||||
for string: String, | |||||
errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>? | |||||
) -> Bool { | |||||
obj?.pointee = "u:\(string)" as AnyObject | |||||
return true | |||||
} | |||||
} |
@@ -1,4 +1,5 @@ | |||||
import BusX | import BusX | ||||
import CordX | |||||
import SwiftUI | import SwiftUI | ||||
struct V: View { | struct V: View { | ||||
@@ -15,7 +16,7 @@ struct V: View { | |||||
.fontWeight(.bold) | .fontWeight(.bold) | ||||
} | } | ||||
TextField("Binding-3", value: $textF.value, formatter: TextFieldValueOwner()) | |||||
TextField("Binding-3", value: $textF.value, formatter: Cord.TextFieldValueOwner()) | |||||
.padding(8) | .padding(8) | ||||
.border(Color.blue, width: 2) | .border(Color.blue, width: 2) | ||||