Skip to content

Commit 142c64e

Browse files
author
GGsrvg
committed
support Combine
1 parent 150a249 commit 142c64e

35 files changed

+884
-210
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.5
1+
// swift-tools-version: 5.8.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

Sample/Sample.xcodeproj/project.pbxproj

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 55;
6+
objectVersion = 56;
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5B2D362B2B1C631A00CF1350 /* BindingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B2D36292B1C631A00CF1350 /* BindingViewController.swift */; };
11+
5B2D362C2B1C631A00CF1350 /* BindingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B2D362A2B1C631A00CF1350 /* BindingViewController.xib */; };
12+
5B2D362E2B1C650B00CF1350 /* BindingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B2D362D2B1C650B00CF1350 /* BindingViewModel.swift */; };
1013
77A204B1287887180089878B /* ColorSortSectionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A204AF287887180089878B /* ColorSortSectionsViewController.swift */; };
1114
77A204B2287887180089878B /* ColorSortSectionsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77A204B0287887180089878B /* ColorSortSectionsViewController.xib */; };
1215
77A204B4287887A90089878B /* ColorSortSectionsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A204B3287887A90089878B /* ColorSortSectionsViewModel.swift */; };
@@ -37,6 +40,9 @@
3740
/* End PBXBuildFile section */
3841

3942
/* Begin PBXFileReference section */
43+
5B2D36292B1C631A00CF1350 /* BindingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingViewController.swift; sourceTree = "<group>"; };
44+
5B2D362A2B1C631A00CF1350 /* BindingViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BindingViewController.xib; sourceTree = "<group>"; };
45+
5B2D362D2B1C650B00CF1350 /* BindingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingViewModel.swift; sourceTree = "<group>"; };
4046
77A204AF287887180089878B /* ColorSortSectionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorSortSectionsViewController.swift; sourceTree = "<group>"; };
4147
77A204B0287887180089878B /* ColorSortSectionsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ColorSortSectionsViewController.xib; sourceTree = "<group>"; };
4248
77A204B3287887A90089878B /* ColorSortSectionsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorSortSectionsViewModel.swift; sourceTree = "<group>"; };
@@ -80,6 +86,16 @@
8086
/* End PBXFrameworksBuildPhase section */
8187

8288
/* Begin PBXGroup section */
89+
5B2D36282B1C630700CF1350 /* Binding */ = {
90+
isa = PBXGroup;
91+
children = (
92+
5B2D362D2B1C650B00CF1350 /* BindingViewModel.swift */,
93+
5B2D36292B1C631A00CF1350 /* BindingViewController.swift */,
94+
5B2D362A2B1C631A00CF1350 /* BindingViewController.xib */,
95+
);
96+
path = Binding;
97+
sourceTree = "<group>";
98+
};
8399
77A204AE287887020089878B /* ColorSortSections */ = {
84100
isa = PBXGroup;
85101
children = (
@@ -137,9 +153,9 @@
137153
77BCC2ED28020998000D83EE /* Pages */ = {
138154
isa = PBXGroup;
139155
children = (
156+
5B2D36282B1C630700CF1350 /* Binding */,
140157
77A204AE287887020089878B /* ColorSortSections */,
141158
77CC1C0C285B113F003E5BF4 /* DiffTableView */,
142-
77D33B36280C577D005CF4BD /* DoubleField */,
143159
77D33B31280C22B9005CF4BD /* Search */,
144160
77DD9C1A2874AF55003881E6 /* ColorSortCollectionView */,
145161
77BCC2EF28020A4A000D83EE /* ColorSort */,
@@ -202,13 +218,6 @@
202218
path = Search;
203219
sourceTree = "<group>";
204220
};
205-
77D33B36280C577D005CF4BD /* DoubleField */ = {
206-
isa = PBXGroup;
207-
children = (
208-
);
209-
path = DoubleField;
210-
sourceTree = "<group>";
211-
};
212221
77DD9C1A2874AF55003881E6 /* ColorSortCollectionView */ = {
213222
isa = PBXGroup;
214223
children = (
@@ -258,7 +267,7 @@
258267
};
259268
};
260269
buildConfigurationList = 77BCC2CF28018240000D83EE /* Build configuration list for PBXProject "Sample" */;
261-
compatibilityVersion = "Xcode 13.0";
270+
compatibilityVersion = "Xcode 14.0";
262271
developmentRegion = en;
263272
hasScannedForEncodings = 0;
264273
knownRegions = (
@@ -284,6 +293,7 @@
284293
77DD9C1E2874AF85003881E6 /* ColorSortCollectionViewController.xib in Resources */,
285294
77BCC2E428018241000D83EE /* LaunchScreen.storyboard in Resources */,
286295
77DD9C192874A39D003881E6 /* DiffTableViewController.xib in Resources */,
296+
5B2D362C2B1C631A00CF1350 /* BindingViewController.xib in Resources */,
287297
77BCC2E128018241000D83EE /* Assets.xcassets in Resources */,
288298
77EE74872872214600D330B6 /* fullNames.txt in Resources */,
289299
77DD9C1128749FFB003881E6 /* ColorSortViewController.xib in Resources */,
@@ -305,8 +315,10 @@
305315
77CC1C10285B11A6003E5BF4 /* DiffTableViewViewModel.swift in Sources */,
306316
77BCC2F628020AFC000D83EE /* UIColor.swift in Sources */,
307317
77BCC2F328020AA8000D83EE /* ColorSortViewModel.swift in Sources */,
318+
5B2D362B2B1C631A00CF1350 /* BindingViewController.swift in Sources */,
308319
77A204B4287887A90089878B /* ColorSortSectionsViewModel.swift in Sources */,
309320
77DD9C142874A0D8003881E6 /* SearchViewController.swift in Sources */,
321+
5B2D362E2B1C650B00CF1350 /* BindingViewModel.swift in Sources */,
310322
77DD9C1028749FFB003881E6 /* ColorSortViewController.swift in Sources */,
311323
77A204B7287897320089878B /* TitleCollectionReusableView.swift in Sources */,
312324
77BCC2D828018240000D83EE /* AppDelegate.swift in Sources */,
@@ -472,7 +484,7 @@
472484
INFOPLIST_KEY_UIMainStoryboardFile = Main;
473485
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
474486
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
475-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
487+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
476488
LD_RUNPATH_SEARCH_PATHS = (
477489
"$(inherited)",
478490
"@executable_path/Frameworks",
@@ -501,7 +513,7 @@
501513
INFOPLIST_KEY_UIMainStoryboardFile = Main;
502514
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
503515
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
504-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
516+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
505517
LD_RUNPATH_SEARCH_PATHS = (
506518
"$(inherited)",
507519
"@executable_path/Frameworks",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// BindingViewController.swift
3+
// Sample
4+
//
5+
// Created by GGsrvg on 03.12.2023.
6+
//
7+
8+
import UIKit
9+
import ObservableField
10+
11+
class BindingViewController: UIViewController {
12+
13+
@IBOutlet weak var textField: UITextField!
14+
@IBOutlet weak var isOnSwitch: UISwitch!
15+
@IBOutlet weak var segmented: UISegmentedControl!
16+
@IBOutlet weak var datePicker: UIDatePicker!
17+
@IBOutlet weak var slider: UISlider!
18+
@IBOutlet weak var colorWell: UIColorWell!
19+
@IBOutlet weak var pageControl: UIPageControl!
20+
21+
@IBOutlet weak var label: UILabel!
22+
23+
private let viewModel = BindingViewModel()
24+
private let cancelContainer = CancelContainer()
25+
26+
deinit {
27+
print("Deinit: \(#fileID)")
28+
}
29+
30+
override func viewDidLoad() {
31+
super.viewDidLoad()
32+
33+
cancelContainer.activate([
34+
textField.textControlProperty <-> viewModel.textSubject,
35+
isOnSwitch.isOnControlProperty <-> viewModel.isOnSubject,
36+
segmented.selectedSegmentedIndexControlProperty <-> viewModel.segmentedSubject,
37+
datePicker.dateControlProperty <-> viewModel.dateSubject,
38+
slider.valueControlProperty <-> viewModel.sliderSubject,
39+
colorWell.colorControlProperty <-> viewModel.colorSubject,
40+
pageControl.currentPageControlProperty <-> viewModel.pageSubject,
41+
42+
viewModel.resultSubject.sink(
43+
receiveCompletion: { _ in },
44+
receiveValue: { [weak self] value in
45+
guard let self else { return }
46+
47+
self.label.text = value
48+
})
49+
])
50+
}
51+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_12" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<objects>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="BindingViewController" customModule="Sample" customModuleProvider="target">
13+
<connections>
14+
<outlet property="colorWell" destination="udn-ZD-HVF" id="Qr2-tR-AQY"/>
15+
<outlet property="datePicker" destination="6bG-qT-ySP" id="rMb-Pe-8Qs"/>
16+
<outlet property="isOnSwitch" destination="MeR-fu-WtO" id="pC2-Ij-cSc"/>
17+
<outlet property="label" destination="ORB-St-c1H" id="R0i-CG-yS5"/>
18+
<outlet property="pageControl" destination="8KU-DW-hkn" id="gfG-sD-Kri"/>
19+
<outlet property="segmented" destination="Of6-BY-eDK" id="f5l-hg-LuO"/>
20+
<outlet property="slider" destination="Abu-qv-Sup" id="SqM-b0-tfu"/>
21+
<outlet property="textField" destination="E4h-HO-5zi" id="Zyv-Hl-vdY"/>
22+
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
23+
</connections>
24+
</placeholder>
25+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
26+
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
27+
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
28+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
29+
<subviews>
30+
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Text" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="E4h-HO-5zi">
31+
<rect key="frame" x="16" y="75" width="361" height="34"/>
32+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
33+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
34+
</textField>
35+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Switch" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WHo-Sa-P5H">
36+
<rect key="frame" x="16" y="121" width="296" height="21"/>
37+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
38+
<nil key="textColor"/>
39+
<nil key="highlightedColor"/>
40+
</label>
41+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MeR-fu-WtO">
42+
<rect key="frame" x="328" y="121" width="51" height="31"/>
43+
</switch>
44+
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Of6-BY-eDK">
45+
<rect key="frame" x="16" y="158" width="361" height="32"/>
46+
<segments>
47+
<segment title="First"/>
48+
<segment title="Second"/>
49+
</segments>
50+
</segmentedControl>
51+
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="6bG-qT-ySP">
52+
<rect key="frame" x="16" y="205" width="361" height="36"/>
53+
</datePicker>
54+
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="23" minValue="0.0" maxValue="100" translatesAutoresizingMaskIntoConstraints="NO" id="Abu-qv-Sup">
55+
<rect key="frame" x="14" y="257" width="365" height="31"/>
56+
</slider>
57+
<colorWell contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="udn-ZD-HVF">
58+
<rect key="frame" x="16" y="303" width="361" height="28"/>
59+
</colorWell>
60+
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" defersCurrentPageDisplay="YES" numberOfPages="11" translatesAutoresizingMaskIntoConstraints="NO" id="8KU-DW-hkn">
61+
<rect key="frame" x="16" y="347" width="361" height="26"/>
62+
<color key="pageIndicatorTintColor" systemColor="systemYellowColor"/>
63+
<color key="currentPageIndicatorTintColor" systemColor="systemBlueColor"/>
64+
</pageControl>
65+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ORB-St-c1H">
66+
<rect key="frame" x="16" y="385" width="361" height="20.333333333333314"/>
67+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
68+
<nil key="textColor"/>
69+
<nil key="highlightedColor"/>
70+
</label>
71+
</subviews>
72+
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
73+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
74+
<constraints>
75+
<constraint firstItem="8KU-DW-hkn" firstAttribute="top" secondItem="udn-ZD-HVF" secondAttribute="bottom" constant="16" id="14h-pp-xtQ"/>
76+
<constraint firstItem="ORB-St-c1H" firstAttribute="top" secondItem="8KU-DW-hkn" secondAttribute="bottom" constant="12" id="1YN-XT-Adp"/>
77+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="ORB-St-c1H" secondAttribute="bottom" constant="12" id="1bP-9g-AzH"/>
78+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="ORB-St-c1H" secondAttribute="trailing" constant="16" id="2o8-7z-lgn"/>
79+
<constraint firstItem="Abu-qv-Sup" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="3wX-b6-Fgc"/>
80+
<constraint firstItem="8KU-DW-hkn" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="4uj-iK-gl5"/>
81+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="MeR-fu-WtO" secondAttribute="trailing" constant="16" id="93A-PM-T58"/>
82+
<constraint firstItem="Of6-BY-eDK" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="F1N-hf-NK6"/>
83+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="Abu-qv-Sup" secondAttribute="trailing" constant="16" id="Fa6-En-mnw"/>
84+
<constraint firstItem="ORB-St-c1H" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="Fn3-Xa-1a5"/>
85+
<constraint firstItem="udn-ZD-HVF" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="FqM-GA-fne"/>
86+
<constraint firstItem="6bG-qT-ySP" firstAttribute="top" secondItem="Of6-BY-eDK" secondAttribute="bottom" constant="16" id="LXO-rT-E9B"/>
87+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="8KU-DW-hkn" secondAttribute="trailing" constant="16" id="OMw-qv-jgm"/>
88+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="udn-ZD-HVF" secondAttribute="trailing" constant="16" id="T9i-d1-1Ps"/>
89+
<constraint firstItem="WHo-Sa-P5H" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="YZ6-3E-rLi"/>
90+
<constraint firstItem="6bG-qT-ySP" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="16" id="Z2P-ib-hZ9"/>
91+
<constraint firstItem="udn-ZD-HVF" firstAttribute="top" secondItem="Abu-qv-Sup" secondAttribute="bottom" constant="16" id="aQ7-GY-gFa"/>
92+
<constraint firstItem="E4h-HO-5zi" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="16" id="dvd-as-j97"/>
93+
<constraint firstItem="WHo-Sa-P5H" firstAttribute="top" secondItem="E4h-HO-5zi" secondAttribute="bottom" constant="12" id="fMk-rW-EYD"/>
94+
<constraint firstItem="Abu-qv-Sup" firstAttribute="top" secondItem="6bG-qT-ySP" secondAttribute="bottom" constant="16" id="fdf-uf-F1s"/>
95+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="Of6-BY-eDK" secondAttribute="trailing" constant="16" id="i0E-Lj-E9x"/>
96+
<constraint firstItem="Of6-BY-eDK" firstAttribute="top" secondItem="WHo-Sa-P5H" secondAttribute="bottom" constant="16" id="lP2-ME-9Oa"/>
97+
<constraint firstItem="MeR-fu-WtO" firstAttribute="top" secondItem="E4h-HO-5zi" secondAttribute="bottom" constant="12" id="lYl-1f-x39"/>
98+
<constraint firstItem="E4h-HO-5zi" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" constant="16" id="lfk-3s-7Wp"/>
99+
<constraint firstItem="MeR-fu-WtO" firstAttribute="leading" secondItem="WHo-Sa-P5H" secondAttribute="trailing" constant="16" id="vUG-pu-Ge0"/>
100+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="E4h-HO-5zi" secondAttribute="trailing" constant="16" id="wI0-vc-mXt"/>
101+
<constraint firstAttribute="trailing" secondItem="6bG-qT-ySP" secondAttribute="trailing" constant="16" id="wbD-hC-6Qu"/>
102+
</constraints>
103+
<point key="canvasLocation" x="138" y="21"/>
104+
</view>
105+
</objects>
106+
<resources>
107+
<systemColor name="systemBackgroundColor">
108+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
109+
</systemColor>
110+
<systemColor name="systemBlueColor">
111+
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
112+
</systemColor>
113+
<systemColor name="systemYellowColor">
114+
<color red="1" green="0.80000000000000004" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
115+
</systemColor>
116+
</resources>
117+
</document>

0 commit comments

Comments
 (0)