From ea09967ab63864b34a509dd1fb71c74c75308430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 28 Dec 2023 12:55:11 +0300 Subject: [PATCH] d --- app/Podfile | 1 + app/Podfile.lock | 8 +++++++- mod/CordX/CordX.podspec | 15 +++++++++++++++ {src => mod/CordX/src}/Cord.Button.swift | 6 +++--- mod/CordX/src/Cord.Onlys.swift | 9 +++++++++ {src => mod/CordX/src}/Cord.Receive.swift | 6 +++--- {src => mod/CordX/src}/Cord.TextField.swift | 11 +++++++---- mod/CordX/src/Cord.TextFieldValueOwner.swift | 19 +++++++++++++++++++ {src => mod/CordX/src}/Cord.swift | 1 - src/Cord.Aux.swift | 8 -------- src/MeetupId.swift | 8 ++++++++ src/TextFieldValueOwner.swift | 17 ----------------- src/V.swift | 3 ++- 13 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 mod/CordX/CordX.podspec rename {src => mod/CordX/src}/Cord.Button.swift (59%) create mode 100644 mod/CordX/src/Cord.Onlys.swift rename {src => mod/CordX/src}/Cord.Receive.swift (74%) rename {src => mod/CordX/src}/Cord.TextField.swift (63%) create mode 100644 mod/CordX/src/Cord.TextFieldValueOwner.swift rename {src => mod/CordX/src}/Cord.swift (95%) delete mode 100644 src/Cord.Aux.swift delete mode 100644 src/TextFieldValueOwner.swift diff --git a/app/Podfile b/app/Podfile index 1136a4c..93c9e12 100644 --- a/app/Podfile +++ b/app/Podfile @@ -4,6 +4,7 @@ platform :ios, '14.0' # Source. pod 'BusX', :path => '../mod/BusX' +pod 'CordX', :path => '../mod/CordX' target 'pesochnicza' do use_frameworks! diff --git a/app/Podfile.lock b/app/Podfile.lock index 34be8bf..c734245 100644 --- a/app/Podfile.lock +++ b/app/Podfile.lock @@ -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 diff --git a/mod/CordX/CordX.podspec b/mod/CordX/CordX.podspec new file mode 100644 index 0000000..491ecdd --- /dev/null +++ b/mod/CordX/CordX.podspec @@ -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 diff --git a/src/Cord.Button.swift b/mod/CordX/src/Cord.Button.swift similarity index 59% rename from src/Cord.Button.swift rename to mod/CordX/src/Cord.Button.swift index 85555e3..c4b4242 100644 --- a/src/Cord.Button.swift +++ b/mod/CordX/src/Cord.Button.swift @@ -2,11 +2,11 @@ import BusX import Combine extension Cord { - final class Button: ObservableObject { - let press = PassthroughSubject() + public final class Button: ObservableObject { + public let press = PassthroughSubject() var subscriptions = [AnyCancellable]() - init(_ key: String) { + public init(_ key: String) { Bus.send( key, press.eraseToAnyPublisher(), diff --git a/mod/CordX/src/Cord.Onlys.swift b/mod/CordX/src/Cord.Onlys.swift new file mode 100644 index 0000000..d616677 --- /dev/null +++ b/mod/CordX/src/Cord.Onlys.swift @@ -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)) + } +} diff --git a/src/Cord.Receive.swift b/mod/CordX/src/Cord.Receive.swift similarity index 74% rename from src/Cord.Receive.swift rename to mod/CordX/src/Cord.Receive.swift index 26f312f..9b8e88a 100644 --- a/src/Cord.Receive.swift +++ b/mod/CordX/src/Cord.Receive.swift @@ -2,11 +2,11 @@ import BusX import Combine extension Cord { - final class Receive: ObservableObject { - @Published var value: T + public final class Receive: ObservableObject { + @Published public var value: T var subscriptions = [AnyCancellable]() - init( + public init( _ key: String, _ defaultValue: T ) { diff --git a/src/Cord.TextField.swift b/mod/CordX/src/Cord.TextField.swift similarity index 63% rename from src/Cord.TextField.swift rename to mod/CordX/src/Cord.TextField.swift index 553d579..4659dec 100644 --- a/src/Cord.TextField.swift +++ b/mod/CordX/src/Cord.TextField.swift @@ -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 ) diff --git a/mod/CordX/src/Cord.TextFieldValueOwner.swift b/mod/CordX/src/Cord.TextFieldValueOwner.swift new file mode 100644 index 0000000..8d470ce --- /dev/null +++ b/mod/CordX/src/Cord.TextFieldValueOwner.swift @@ -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?, + for string: String, + errorDescription error: AutoreleasingUnsafeMutablePointer? + ) -> Bool { + obj?.pointee = "u:\(string)" as AnyObject + return true + } + } +} diff --git a/src/Cord.swift b/mod/CordX/src/Cord.swift similarity index 95% rename from src/Cord.swift rename to mod/CordX/src/Cord.swift index f40341f..f050533 100644 --- a/src/Cord.swift +++ b/mod/CordX/src/Cord.swift @@ -1,2 +1 @@ - public enum Cord { } diff --git a/src/Cord.Aux.swift b/src/Cord.Aux.swift deleted file mode 100644 index e2dc6c3..0000000 --- a/src/Cord.Aux.swift +++ /dev/null @@ -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)) -} diff --git a/src/MeetupId.swift b/src/MeetupId.swift index f0a609c..876e856 100644 --- a/src/MeetupId.swift +++ b/src/MeetupId.swift @@ -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)) +} } diff --git a/src/TextFieldValueOwner.swift b/src/TextFieldValueOwner.swift deleted file mode 100644 index fc80728..0000000 --- a/src/TextFieldValueOwner.swift +++ /dev/null @@ -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?, - for string: String, - errorDescription error: AutoreleasingUnsafeMutablePointer? - ) -> Bool { - obj?.pointee = "u:\(string)" as AnyObject - return true - } -} diff --git a/src/V.swift b/src/V.swift index b4ff976..47cf127 100644 --- a/src/V.swift +++ b/src/V.swift @@ -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)