This commit is contained in:
Михаил Капелько
2023-12-28 12:55:11 +03:00
parent eb29bb6d9e
commit ea09967ab6
13 changed files with 74 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ platform :ios, '14.0'
# Source.
pod 'BusX', :path => '../mod/BusX'
pod 'CordX', :path => '../mod/CordX'
target 'pesochnicza' do
use_frameworks!

View File

@@ -1,16 +1,22 @@
PODS:
- BusX (2023.12.28)
- CordX (2023.12.28):
- BusX
DEPENDENCIES:
- BusX (from `../mod/BusX`)
- CordX (from `../mod/CordX`)
EXTERNAL SOURCES:
BusX:
:path: "../mod/BusX"
CordX:
:path: "../mod/CordX"
SPEC CHECKSUMS:
BusX: fd22c04ad544d131e66315c1a33d87d85b19712e
CordX: 63515d366b217366b9562edcfef34630a7be1171
PODFILE CHECKSUM: c4bbd7cc826ceee472b0bbb53eb2d5dc7dd1f97e
PODFILE CHECKSUM: 1091fc5c43b2a3881ee63b88848d7ed4f2ede026
COCOAPODS: 1.13.0

15
mod/CordX/CordX.podspec Normal file
View 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

View File

@@ -2,11 +2,11 @@ import BusX
import Combine
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]()
init(_ key: String) {
public init(_ key: String) {
Bus.send(
key,
press.eraseToAnyPublisher(),

View 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))
}
}

View File

@@ -2,11 +2,11 @@ import BusX
import Combine
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]()
init(
public init(
_ key: String,
_ defaultValue: T
) {

View File

@@ -3,17 +3,20 @@ import Combine
import SwiftUI
extension Cord {
final class TextField: ObservableObject {
@Published var value = "a:"
public final class TextField: ObservableObject {
@Published public var value = "a:"
var subscriptions = [AnyCancellable]()
init(
public init(
_ textApp: String,
_ textUI: String
) {
Bus.send(
textUI,
$value.removeDuplicates().compactMap(onlyUIText).eraseToAnyPublisher(),
$value
.removeDuplicates()
.compactMap(onlyUIText)
.eraseToAnyPublisher(),
sub: &subscriptions
)

View 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
}
}
}

View File

@@ -1,2 +1 @@
public enum Cord { }

View File

@@ -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))
}

View File

@@ -29,6 +29,14 @@ enum MeetupId {
}
return r
}
/// Пропускаем лишь значения от UI
///
/// - Returns: Значение без префиксов "a:"/"u:"
func onlyUIText(_ s: String) -> String? {
guard s.hasPrefix("u:") else { return nil }
return String(s.dropFirst(2))
}
}

View File

@@ -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
}
}

View File

@@ -1,4 +1,5 @@
import BusX
import CordX
import SwiftUI
struct V: View {
@@ -15,7 +16,7 @@ struct V: View {
.fontWeight(.bold)
}
TextField("Binding-3", value: $textF.value, formatter: TextFieldValueOwner())
TextField("Binding-3", value: $textF.value, formatter: Cord.TextFieldValueOwner())
.padding(8)
.border(Color.blue, width: 2)