├── .gitignore ├── .travis.yml ├── Example ├── Podfile ├── Podfile.lock ├── SimpleTwoWayBinding.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── SimpleTwoWayBinding-Example.xcscheme ├── SimpleTwoWayBinding.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── SimpleTwoWayBinding │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── FormViewModel.swift │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── SubmissionViewController.swift │ └── ViewController.swift └── Tests │ └── Info.plist ├── LICENSE ├── README.md ├── SimpleTwoWayBinding.podspec ├── Sources ├── Bindable.swift ├── BlockBasedSelector │ ├── BlockBasedSelector.h │ ├── BlockBasedSelector.m │ └── BlockBasedSelector.swift ├── NSObject+Observable.swift ├── Observable.swift ├── SimpleTwoWayBindings-Bridging-Header.h └── UIControls+Bindable.swift └── doc └── diag.jpeg /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | Carthage 26 | # We recommend against adding the Pods directory to your .gitignore. However 27 | # you should judge for yourself, the pros and cons are mentioned at: 28 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 29 | # 30 | # Note: if you ignore the Pods directory, make sure to uncomment 31 | # `pod install` in .travis.yml 32 | # 33 | Pods/ 34 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * http://www.objc.io/issue-6/travis-ci.html 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | osx_image: xcode11 6 | language: swift 7 | # cache: cocoapods 8 | # podfile: Example/Podfile 9 | # before_install: 10 | # - gem install cocoapods # Since Travis is not always on latest version 11 | # - pod install --project-directory=Example 12 | script: 13 | - pod lib lint 14 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | target 'SimpleTwoWayBinding_Example' do 4 | pod 'SimpleTwoWayBinding', :path => '../' 5 | 6 | target 'SimpleTwoWayBinding_Tests' do 7 | inherit! :search_paths 8 | 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Example/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - SimpleTwoWayBinding (0.0.1) 3 | 4 | DEPENDENCIES: 5 | - SimpleTwoWayBinding (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | SimpleTwoWayBinding: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | SimpleTwoWayBinding: e33dcbffd4829c023752b8a40a1aa2cb59743f6d 13 | 14 | PODFILE CHECKSUM: 4a3fccefb97b1064aec7a3d86ef38fa3f63e817f 15 | 16 | COCOAPODS: 1.7.5 17 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 09C8E51F42157CCCA60C9CC2 /* Pods_SimpleTwoWayBinding_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AC4ADABBEF628BE0FEFCC0A /* Pods_SimpleTwoWayBinding_Tests.framework */; }; 11 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 12 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 13 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; 14 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 15 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 16 | 60CBB9A785FFAC65379F34B5 /* Pods_SimpleTwoWayBinding_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DECF1B4ADB1D518ACA3E8DA1 /* Pods_SimpleTwoWayBinding_Example.framework */; }; 17 | 907EFE3D1FCAE2CB00BA2201 /* FormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907EFE3C1FCAE2CB00BA2201 /* FormViewModel.swift */; }; 18 | 907EFE3F1FCAEBCE00BA2201 /* SubmissionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907EFE3E1FCAEBCE00BA2201 /* SubmissionViewController.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 607FACC81AFB9204008FA782 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 607FACCF1AFB9204008FA782; 27 | remoteInfo = SimpleTwoWayBinding; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 05D92C2D676B6C38C182F90F /* Pods-SimpleTwoWayBinding_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleTwoWayBinding_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleTwoWayBinding_Tests/Pods-SimpleTwoWayBinding_Tests.release.xcconfig"; sourceTree = ""; }; 33 | 607FACD01AFB9204008FA782 /* SimpleTwoWayBinding_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleTwoWayBinding_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 37 | 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 39 | 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 40 | 607FACE51AFB9204008FA782 /* SimpleTwoWayBinding_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SimpleTwoWayBinding_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 61BFE1793C0EBEF5BF29A299 /* Pods-SimpleTwoWayBinding_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleTwoWayBinding_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleTwoWayBinding_Example/Pods-SimpleTwoWayBinding_Example.debug.xcconfig"; sourceTree = ""; }; 43 | 6AC4ADABBEF628BE0FEFCC0A /* Pods_SimpleTwoWayBinding_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SimpleTwoWayBinding_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 708F6D4EDD801D7A9CB93DCB /* SimpleTwoWayBinding.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SimpleTwoWayBinding.podspec; path = ../SimpleTwoWayBinding.podspec; sourceTree = ""; }; 45 | 907EFE3C1FCAE2CB00BA2201 /* FormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormViewModel.swift; sourceTree = ""; }; 46 | 907EFE3E1FCAEBCE00BA2201 /* SubmissionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubmissionViewController.swift; sourceTree = ""; }; 47 | BC8231F8B99256B7738E8193 /* Pods-SimpleTwoWayBinding_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleTwoWayBinding_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleTwoWayBinding_Example/Pods-SimpleTwoWayBinding_Example.release.xcconfig"; sourceTree = ""; }; 48 | C9A42E9AA7EAB0C62E1E7769 /* Pods-SimpleTwoWayBinding_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleTwoWayBinding_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SimpleTwoWayBinding_Tests/Pods-SimpleTwoWayBinding_Tests.debug.xcconfig"; sourceTree = ""; }; 49 | DECF1B4ADB1D518ACA3E8DA1 /* Pods_SimpleTwoWayBinding_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SimpleTwoWayBinding_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | F0CB457EB75EFEB83CD78942 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 51 | FB30028F024D40607E1F4DB4 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 52 | /* End PBXFileReference section */ 53 | 54 | /* Begin PBXFrameworksBuildPhase section */ 55 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | 60CBB9A785FFAC65379F34B5 /* Pods_SimpleTwoWayBinding_Example.framework in Frameworks */, 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | 607FACE21AFB9204008FA782 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | 09C8E51F42157CCCA60C9CC2 /* Pods_SimpleTwoWayBinding_Tests.framework in Frameworks */, 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | /* End PBXFrameworksBuildPhase section */ 72 | 73 | /* Begin PBXGroup section */ 74 | 607FACC71AFB9204008FA782 = { 75 | isa = PBXGroup; 76 | children = ( 77 | 607FACF51AFB993E008FA782 /* Podspec Metadata */, 78 | 607FACD21AFB9204008FA782 /* Example for SimpleTwoWayBinding */, 79 | 607FACE81AFB9204008FA782 /* Tests */, 80 | 607FACD11AFB9204008FA782 /* Products */, 81 | 83A4CD32863FC4040998ACAF /* Pods */, 82 | A7D49290BE6BD99F0602AEB4 /* Frameworks */, 83 | ); 84 | sourceTree = ""; 85 | }; 86 | 607FACD11AFB9204008FA782 /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 607FACD01AFB9204008FA782 /* SimpleTwoWayBinding_Example.app */, 90 | 607FACE51AFB9204008FA782 /* SimpleTwoWayBinding_Tests.xctest */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 607FACD21AFB9204008FA782 /* Example for SimpleTwoWayBinding */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */, 99 | 607FACD71AFB9204008FA782 /* ViewController.swift */, 100 | 907EFE3E1FCAEBCE00BA2201 /* SubmissionViewController.swift */, 101 | 607FACD91AFB9204008FA782 /* Main.storyboard */, 102 | 607FACDC1AFB9204008FA782 /* Images.xcassets */, 103 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 104 | 607FACD31AFB9204008FA782 /* Supporting Files */, 105 | 907EFE3C1FCAE2CB00BA2201 /* FormViewModel.swift */, 106 | ); 107 | name = "Example for SimpleTwoWayBinding"; 108 | path = SimpleTwoWayBinding; 109 | sourceTree = ""; 110 | }; 111 | 607FACD31AFB9204008FA782 /* Supporting Files */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 607FACD41AFB9204008FA782 /* Info.plist */, 115 | ); 116 | name = "Supporting Files"; 117 | sourceTree = ""; 118 | }; 119 | 607FACE81AFB9204008FA782 /* Tests */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 607FACE91AFB9204008FA782 /* Supporting Files */, 123 | ); 124 | path = Tests; 125 | sourceTree = ""; 126 | }; 127 | 607FACE91AFB9204008FA782 /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 607FACEA1AFB9204008FA782 /* Info.plist */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 708F6D4EDD801D7A9CB93DCB /* SimpleTwoWayBinding.podspec */, 139 | FB30028F024D40607E1F4DB4 /* README.md */, 140 | F0CB457EB75EFEB83CD78942 /* LICENSE */, 141 | ); 142 | name = "Podspec Metadata"; 143 | sourceTree = ""; 144 | }; 145 | 83A4CD32863FC4040998ACAF /* Pods */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 61BFE1793C0EBEF5BF29A299 /* Pods-SimpleTwoWayBinding_Example.debug.xcconfig */, 149 | BC8231F8B99256B7738E8193 /* Pods-SimpleTwoWayBinding_Example.release.xcconfig */, 150 | C9A42E9AA7EAB0C62E1E7769 /* Pods-SimpleTwoWayBinding_Tests.debug.xcconfig */, 151 | 05D92C2D676B6C38C182F90F /* Pods-SimpleTwoWayBinding_Tests.release.xcconfig */, 152 | ); 153 | name = Pods; 154 | sourceTree = ""; 155 | }; 156 | A7D49290BE6BD99F0602AEB4 /* Frameworks */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | DECF1B4ADB1D518ACA3E8DA1 /* Pods_SimpleTwoWayBinding_Example.framework */, 160 | 6AC4ADABBEF628BE0FEFCC0A /* Pods_SimpleTwoWayBinding_Tests.framework */, 161 | ); 162 | name = Frameworks; 163 | sourceTree = ""; 164 | }; 165 | /* End PBXGroup section */ 166 | 167 | /* Begin PBXNativeTarget section */ 168 | 607FACCF1AFB9204008FA782 /* SimpleTwoWayBinding_Example */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SimpleTwoWayBinding_Example" */; 171 | buildPhases = ( 172 | 0E51555D35BB61E84714456F /* [CP] Check Pods Manifest.lock */, 173 | 607FACCC1AFB9204008FA782 /* Sources */, 174 | 607FACCD1AFB9204008FA782 /* Frameworks */, 175 | 607FACCE1AFB9204008FA782 /* Resources */, 176 | D5FC30208E09CFEDE4AA3229 /* [CP] Embed Pods Frameworks */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | ); 182 | name = SimpleTwoWayBinding_Example; 183 | productName = SimpleTwoWayBinding; 184 | productReference = 607FACD01AFB9204008FA782 /* SimpleTwoWayBinding_Example.app */; 185 | productType = "com.apple.product-type.application"; 186 | }; 187 | 607FACE41AFB9204008FA782 /* SimpleTwoWayBinding_Tests */ = { 188 | isa = PBXNativeTarget; 189 | buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SimpleTwoWayBinding_Tests" */; 190 | buildPhases = ( 191 | 3ED7A00782A4D9F90B68EBD0 /* [CP] Check Pods Manifest.lock */, 192 | 607FACE11AFB9204008FA782 /* Sources */, 193 | 607FACE21AFB9204008FA782 /* Frameworks */, 194 | 607FACE31AFB9204008FA782 /* Resources */, 195 | ); 196 | buildRules = ( 197 | ); 198 | dependencies = ( 199 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */, 200 | ); 201 | name = SimpleTwoWayBinding_Tests; 202 | productName = Tests; 203 | productReference = 607FACE51AFB9204008FA782 /* SimpleTwoWayBinding_Tests.xctest */; 204 | productType = "com.apple.product-type.bundle.unit-test"; 205 | }; 206 | /* End PBXNativeTarget section */ 207 | 208 | /* Begin PBXProject section */ 209 | 607FACC81AFB9204008FA782 /* Project object */ = { 210 | isa = PBXProject; 211 | attributes = { 212 | LastSwiftUpdateCheck = 0830; 213 | LastUpgradeCheck = 1100; 214 | ORGANIZATIONNAME = CocoaPods; 215 | TargetAttributes = { 216 | 607FACCF1AFB9204008FA782 = { 217 | CreatedOnToolsVersion = 6.3.1; 218 | DevelopmentTeam = W38J75Z9CF; 219 | LastSwiftMigration = 0900; 220 | }; 221 | 607FACE41AFB9204008FA782 = { 222 | CreatedOnToolsVersion = 6.3.1; 223 | LastSwiftMigration = 0900; 224 | TestTargetID = 607FACCF1AFB9204008FA782; 225 | }; 226 | }; 227 | }; 228 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "SimpleTwoWayBinding" */; 229 | compatibilityVersion = "Xcode 3.2"; 230 | developmentRegion = English; 231 | hasScannedForEncodings = 0; 232 | knownRegions = ( 233 | English, 234 | en, 235 | Base, 236 | ); 237 | mainGroup = 607FACC71AFB9204008FA782; 238 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 239 | projectDirPath = ""; 240 | projectRoot = ""; 241 | targets = ( 242 | 607FACCF1AFB9204008FA782 /* SimpleTwoWayBinding_Example */, 243 | 607FACE41AFB9204008FA782 /* SimpleTwoWayBinding_Tests */, 244 | ); 245 | }; 246 | /* End PBXProject section */ 247 | 248 | /* Begin PBXResourcesBuildPhase section */ 249 | 607FACCE1AFB9204008FA782 /* Resources */ = { 250 | isa = PBXResourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 254 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 255 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | 607FACE31AFB9204008FA782 /* Resources */ = { 260 | isa = PBXResourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXResourcesBuildPhase section */ 267 | 268 | /* Begin PBXShellScriptBuildPhase section */ 269 | 0E51555D35BB61E84714456F /* [CP] Check Pods Manifest.lock */ = { 270 | isa = PBXShellScriptBuildPhase; 271 | buildActionMask = 2147483647; 272 | files = ( 273 | ); 274 | inputPaths = ( 275 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 276 | "${PODS_ROOT}/Manifest.lock", 277 | ); 278 | name = "[CP] Check Pods Manifest.lock"; 279 | outputPaths = ( 280 | "$(DERIVED_FILE_DIR)/Pods-SimpleTwoWayBinding_Example-checkManifestLockResult.txt", 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | shellPath = /bin/sh; 284 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 285 | showEnvVarsInLog = 0; 286 | }; 287 | 3ED7A00782A4D9F90B68EBD0 /* [CP] Check Pods Manifest.lock */ = { 288 | isa = PBXShellScriptBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | ); 292 | inputPaths = ( 293 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 294 | "${PODS_ROOT}/Manifest.lock", 295 | ); 296 | name = "[CP] Check Pods Manifest.lock"; 297 | outputPaths = ( 298 | "$(DERIVED_FILE_DIR)/Pods-SimpleTwoWayBinding_Tests-checkManifestLockResult.txt", 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | shellPath = /bin/sh; 302 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 303 | showEnvVarsInLog = 0; 304 | }; 305 | D5FC30208E09CFEDE4AA3229 /* [CP] Embed Pods Frameworks */ = { 306 | isa = PBXShellScriptBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | ); 310 | inputPaths = ( 311 | "${PODS_ROOT}/Target Support Files/Pods-SimpleTwoWayBinding_Example/Pods-SimpleTwoWayBinding_Example-frameworks.sh", 312 | "${BUILT_PRODUCTS_DIR}/SimpleTwoWayBinding/SimpleTwoWayBinding.framework", 313 | ); 314 | name = "[CP] Embed Pods Frameworks"; 315 | outputPaths = ( 316 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SimpleTwoWayBinding.framework", 317 | ); 318 | runOnlyForDeploymentPostprocessing = 0; 319 | shellPath = /bin/sh; 320 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SimpleTwoWayBinding_Example/Pods-SimpleTwoWayBinding_Example-frameworks.sh\"\n"; 321 | showEnvVarsInLog = 0; 322 | }; 323 | /* End PBXShellScriptBuildPhase section */ 324 | 325 | /* Begin PBXSourcesBuildPhase section */ 326 | 607FACCC1AFB9204008FA782 /* Sources */ = { 327 | isa = PBXSourcesBuildPhase; 328 | buildActionMask = 2147483647; 329 | files = ( 330 | 907EFE3F1FCAEBCE00BA2201 /* SubmissionViewController.swift in Sources */, 331 | 907EFE3D1FCAE2CB00BA2201 /* FormViewModel.swift in Sources */, 332 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 333 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, 334 | ); 335 | runOnlyForDeploymentPostprocessing = 0; 336 | }; 337 | 607FACE11AFB9204008FA782 /* Sources */ = { 338 | isa = PBXSourcesBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | ); 342 | runOnlyForDeploymentPostprocessing = 0; 343 | }; 344 | /* End PBXSourcesBuildPhase section */ 345 | 346 | /* Begin PBXTargetDependency section */ 347 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */ = { 348 | isa = PBXTargetDependency; 349 | target = 607FACCF1AFB9204008FA782 /* SimpleTwoWayBinding_Example */; 350 | targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */; 351 | }; 352 | /* End PBXTargetDependency section */ 353 | 354 | /* Begin PBXVariantGroup section */ 355 | 607FACD91AFB9204008FA782 /* Main.storyboard */ = { 356 | isa = PBXVariantGroup; 357 | children = ( 358 | 607FACDA1AFB9204008FA782 /* Base */, 359 | ); 360 | name = Main.storyboard; 361 | sourceTree = ""; 362 | }; 363 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { 364 | isa = PBXVariantGroup; 365 | children = ( 366 | 607FACDF1AFB9204008FA782 /* Base */, 367 | ); 368 | name = LaunchScreen.xib; 369 | sourceTree = ""; 370 | }; 371 | /* End PBXVariantGroup section */ 372 | 373 | /* Begin XCBuildConfiguration section */ 374 | 607FACED1AFB9204008FA782 /* Debug */ = { 375 | isa = XCBuildConfiguration; 376 | buildSettings = { 377 | ALWAYS_SEARCH_USER_PATHS = NO; 378 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 379 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 380 | CLANG_CXX_LIBRARY = "libc++"; 381 | CLANG_ENABLE_MODULES = YES; 382 | CLANG_ENABLE_OBJC_ARC = YES; 383 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 384 | CLANG_WARN_BOOL_CONVERSION = YES; 385 | CLANG_WARN_COMMA = YES; 386 | CLANG_WARN_CONSTANT_CONVERSION = YES; 387 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 388 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 389 | CLANG_WARN_EMPTY_BODY = YES; 390 | CLANG_WARN_ENUM_CONVERSION = YES; 391 | CLANG_WARN_INFINITE_RECURSION = YES; 392 | CLANG_WARN_INT_CONVERSION = YES; 393 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 394 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 395 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 396 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 397 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 398 | CLANG_WARN_STRICT_PROTOTYPES = YES; 399 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 400 | CLANG_WARN_UNREACHABLE_CODE = YES; 401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 402 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 403 | COPY_PHASE_STRIP = NO; 404 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 405 | ENABLE_STRICT_OBJC_MSGSEND = YES; 406 | ENABLE_TESTABILITY = YES; 407 | GCC_C_LANGUAGE_STANDARD = gnu99; 408 | GCC_DYNAMIC_NO_PIC = NO; 409 | GCC_NO_COMMON_BLOCKS = YES; 410 | GCC_OPTIMIZATION_LEVEL = 0; 411 | GCC_PREPROCESSOR_DEFINITIONS = ( 412 | "DEBUG=1", 413 | "$(inherited)", 414 | ); 415 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 416 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 417 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 418 | GCC_WARN_UNDECLARED_SELECTOR = YES; 419 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 420 | GCC_WARN_UNUSED_FUNCTION = YES; 421 | GCC_WARN_UNUSED_VARIABLE = YES; 422 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 423 | MTL_ENABLE_DEBUG_INFO = YES; 424 | ONLY_ACTIVE_ARCH = YES; 425 | SDKROOT = iphoneos; 426 | SWIFT_COMPILATION_MODE = wholemodule; 427 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 428 | SWIFT_VERSION = 5.0; 429 | }; 430 | name = Debug; 431 | }; 432 | 607FACEE1AFB9204008FA782 /* Release */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ALWAYS_SEARCH_USER_PATHS = NO; 436 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 437 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 438 | CLANG_CXX_LIBRARY = "libc++"; 439 | CLANG_ENABLE_MODULES = YES; 440 | CLANG_ENABLE_OBJC_ARC = YES; 441 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 442 | CLANG_WARN_BOOL_CONVERSION = YES; 443 | CLANG_WARN_COMMA = YES; 444 | CLANG_WARN_CONSTANT_CONVERSION = YES; 445 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 446 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 447 | CLANG_WARN_EMPTY_BODY = YES; 448 | CLANG_WARN_ENUM_CONVERSION = YES; 449 | CLANG_WARN_INFINITE_RECURSION = YES; 450 | CLANG_WARN_INT_CONVERSION = YES; 451 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 452 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 453 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 454 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 455 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 456 | CLANG_WARN_STRICT_PROTOTYPES = YES; 457 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 458 | CLANG_WARN_UNREACHABLE_CODE = YES; 459 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 460 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 461 | COPY_PHASE_STRIP = NO; 462 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 463 | ENABLE_NS_ASSERTIONS = NO; 464 | ENABLE_STRICT_OBJC_MSGSEND = YES; 465 | GCC_C_LANGUAGE_STANDARD = gnu99; 466 | GCC_NO_COMMON_BLOCKS = YES; 467 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 468 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 469 | GCC_WARN_UNDECLARED_SELECTOR = YES; 470 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 471 | GCC_WARN_UNUSED_FUNCTION = YES; 472 | GCC_WARN_UNUSED_VARIABLE = YES; 473 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 474 | MTL_ENABLE_DEBUG_INFO = NO; 475 | SDKROOT = iphoneos; 476 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 477 | SWIFT_VERSION = 5.0; 478 | VALIDATE_PRODUCT = YES; 479 | }; 480 | name = Release; 481 | }; 482 | 607FACF01AFB9204008FA782 /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | baseConfigurationReference = 61BFE1793C0EBEF5BF29A299 /* Pods-SimpleTwoWayBinding_Example.debug.xcconfig */; 485 | buildSettings = { 486 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 487 | DEVELOPMENT_TEAM = W38J75Z9CF; 488 | INFOPLIST_FILE = SimpleTwoWayBinding/Info.plist; 489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 490 | MODULE_NAME = ExampleApp; 491 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 492 | PRODUCT_NAME = "$(TARGET_NAME)"; 493 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 494 | SWIFT_VERSION = 5.0; 495 | }; 496 | name = Debug; 497 | }; 498 | 607FACF11AFB9204008FA782 /* Release */ = { 499 | isa = XCBuildConfiguration; 500 | baseConfigurationReference = BC8231F8B99256B7738E8193 /* Pods-SimpleTwoWayBinding_Example.release.xcconfig */; 501 | buildSettings = { 502 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 503 | DEVELOPMENT_TEAM = W38J75Z9CF; 504 | INFOPLIST_FILE = SimpleTwoWayBinding/Info.plist; 505 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 506 | MODULE_NAME = ExampleApp; 507 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 508 | PRODUCT_NAME = "$(TARGET_NAME)"; 509 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 510 | SWIFT_VERSION = 5.0; 511 | }; 512 | name = Release; 513 | }; 514 | 607FACF31AFB9204008FA782 /* Debug */ = { 515 | isa = XCBuildConfiguration; 516 | baseConfigurationReference = C9A42E9AA7EAB0C62E1E7769 /* Pods-SimpleTwoWayBinding_Tests.debug.xcconfig */; 517 | buildSettings = { 518 | FRAMEWORK_SEARCH_PATHS = ( 519 | "$(SDKROOT)/Developer/Library/Frameworks", 520 | "$(inherited)", 521 | ); 522 | GCC_PREPROCESSOR_DEFINITIONS = ( 523 | "DEBUG=1", 524 | "$(inherited)", 525 | ); 526 | INFOPLIST_FILE = Tests/Info.plist; 527 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 528 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 529 | PRODUCT_NAME = "$(TARGET_NAME)"; 530 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 531 | SWIFT_VERSION = 5.0; 532 | }; 533 | name = Debug; 534 | }; 535 | 607FACF41AFB9204008FA782 /* Release */ = { 536 | isa = XCBuildConfiguration; 537 | baseConfigurationReference = 05D92C2D676B6C38C182F90F /* Pods-SimpleTwoWayBinding_Tests.release.xcconfig */; 538 | buildSettings = { 539 | FRAMEWORK_SEARCH_PATHS = ( 540 | "$(SDKROOT)/Developer/Library/Frameworks", 541 | "$(inherited)", 542 | ); 543 | INFOPLIST_FILE = Tests/Info.plist; 544 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 545 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 546 | PRODUCT_NAME = "$(TARGET_NAME)"; 547 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 548 | SWIFT_VERSION = 5.0; 549 | }; 550 | name = Release; 551 | }; 552 | /* End XCBuildConfiguration section */ 553 | 554 | /* Begin XCConfigurationList section */ 555 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "SimpleTwoWayBinding" */ = { 556 | isa = XCConfigurationList; 557 | buildConfigurations = ( 558 | 607FACED1AFB9204008FA782 /* Debug */, 559 | 607FACEE1AFB9204008FA782 /* Release */, 560 | ); 561 | defaultConfigurationIsVisible = 0; 562 | defaultConfigurationName = Release; 563 | }; 564 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SimpleTwoWayBinding_Example" */ = { 565 | isa = XCConfigurationList; 566 | buildConfigurations = ( 567 | 607FACF01AFB9204008FA782 /* Debug */, 568 | 607FACF11AFB9204008FA782 /* Release */, 569 | ); 570 | defaultConfigurationIsVisible = 0; 571 | defaultConfigurationName = Release; 572 | }; 573 | 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "SimpleTwoWayBinding_Tests" */ = { 574 | isa = XCConfigurationList; 575 | buildConfigurations = ( 576 | 607FACF31AFB9204008FA782 /* Debug */, 577 | 607FACF41AFB9204008FA782 /* Release */, 578 | ); 579 | defaultConfigurationIsVisible = 0; 580 | defaultConfigurationName = Release; 581 | }; 582 | /* End XCConfigurationList section */ 583 | }; 584 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 585 | } 586 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding.xcodeproj/xcshareddata/xcschemes/SimpleTwoWayBinding-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 51 | 52 | 53 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 76 | 78 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/2017. 6 | // Copyright (c) 2017 Manish Katoch. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 61 | 67 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 84 | 90 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/FormViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FormViewModel.swift 3 | // SimpleTwoWayBinding_Example 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // Copyright © 2017 CocoaPods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SimpleTwoWayBinding 11 | 12 | struct FormViewModel { 13 | let name: Observable = Observable() 14 | let companyName: Observable = Observable() 15 | let yearsOfExperience: Observable = Observable() 16 | let isCurrentEmployer: Observable = Observable(false) 17 | let approxSalary: Observable = Observable() 18 | let comments: Observable = Observable() 19 | 20 | func getExperienceString() -> String { 21 | if let yearsOfExperience = yearsOfExperience.value { 22 | return "\(String(describing: yearsOfExperience)) yrs" 23 | } 24 | return "--" 25 | } 26 | 27 | func getSalaryString() -> String { 28 | if let approxSalary = approxSalary.value { 29 | let normalizedValue = approxSalary / 1000.0 30 | return "\(normalizedValue)k" 31 | 32 | } 33 | return "--" 34 | } 35 | 36 | func getPrettyString() -> String { 37 | return 38 | "Name: \(String(describing: name.value ?? "--"))\n" + 39 | "Company: \(String(describing: companyName.value ?? "--"))\n" + 40 | "Experience: \(getExperienceString())\n" + 41 | "Current Employer?: \(((isCurrentEmployer.value ?? false) ? "YES" : "NO"))\n" + 42 | "approx Salary: \(getSalaryString())\n" + 43 | "Comments: \(String(describing: comments.value ?? "--"))" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/SubmissionViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SubmissionViewController.swift 3 | // SimpleTwoWayBinding_Example 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // Copyright © 2017 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SubmissionViewController: UIViewController { 12 | 13 | var submissionString: String = "--" 14 | 15 | @IBOutlet weak var submissionTextView: UITextView! 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | // Do any additional setup after loading the view. 20 | } 21 | 22 | override func viewWillAppear(_ animated: Bool) { 23 | super.viewWillAppear(animated) 24 | self.navigationItem.title = "View Your Submission" 25 | self.navigationItem.backBarButtonItem?.title = "BACK" 26 | submissionTextView.text = submissionString 27 | } 28 | 29 | override func didReceiveMemoryWarning() { 30 | super.didReceiveMemoryWarning() 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Example/SimpleTwoWayBinding/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/2017. 6 | // Copyright (c) 2017 Manish Katoch. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SimpleTwoWayBinding 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var nameField: UITextField! 15 | @IBOutlet weak var companyField: UITextField! 16 | @IBOutlet weak var isCurrentEmployerSwitch: UISwitch! 17 | @IBOutlet weak var yearsOfExperienceStepper: UIStepper! 18 | @IBOutlet weak var commentsView: BindableTextView! { 19 | didSet { 20 | commentsView.layer.borderColor = UIColor.lightGray.cgColor 21 | commentsView.layer.cornerRadius = 5.0 22 | commentsView.layer.borderWidth = 1.0 23 | } 24 | } 25 | @IBOutlet weak var salaryRangeSlider: UISlider! 26 | 27 | @IBOutlet weak var selectedSalaryRangeLabel: UILabel! 28 | @IBOutlet weak var selectedYearsOfExperienceLabel: UILabel! 29 | 30 | var viewModel: FormViewModel! 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | viewModel = FormViewModel() 35 | } 36 | 37 | override func viewWillAppear(_ animated: Bool) { 38 | super.viewWillAppear(animated) 39 | self.navigationItem.title = "Survey Form" 40 | setupBindings() 41 | } 42 | 43 | func setupBindings() { 44 | nameField.bind(with: viewModel.name) 45 | companyField.bind(with: viewModel.companyName) 46 | isCurrentEmployerSwitch.bind(with: viewModel.isCurrentEmployer) 47 | yearsOfExperienceStepper.bind(with: viewModel.yearsOfExperience) 48 | salaryRangeSlider.bind(with: viewModel.approxSalary) 49 | commentsView.bind(with: viewModel.comments) 50 | 51 | selectedSalaryRangeLabel.observe(for: viewModel.approxSalary) { 52 | [unowned self](_) in 53 | self.selectedSalaryRangeLabel.text = 54 | self.viewModel.getSalaryString() 55 | } 56 | 57 | selectedYearsOfExperienceLabel.observe(for: viewModel.yearsOfExperience) { 58 | [unowned self](_) in 59 | self.selectedYearsOfExperienceLabel.text = 60 | self.viewModel.getExperienceString() 61 | } 62 | } 63 | 64 | @IBAction func salaryRangeSliderValueChanged(_ sender: UISlider) { 65 | let roundedValue = round(sender.value / 1000.0) * 1000.0 66 | sender.value = roundedValue 67 | } 68 | 69 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 70 | if segue.identifier == "showSubmission" { 71 | if let vc = segue.destination as? SubmissionViewController { 72 | vc.submissionString = viewModel.getPrettyString() 73 | } 74 | } 75 | } 76 | 77 | @IBAction func submitFormTapped(_ sender: Any) { 78 | 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /Example/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Manish Katoch 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## update: 08/24/2019 2 | 3 | This repository was created for demonstration purpose rather than for consumption. However, given the feedback and usage of this repository, I will start maintaining it here-on and priortize fixing/implementing raised issues. 4 | 5 | 6 | # SimpleTwoWayBinding for iOS 7 | 8 | [![Version](https://img.shields.io/cocoapods/v/SimpleTwoWayBinding.svg?style=flat)](http://cocoapods.org/pods/SimpleTwoWayBinding) 9 | [![License](https://img.shields.io/cocoapods/l/SimpleTwoWayBinding.svg?style=flat)](http://cocoapods.org/pods/SimpleTwoWayBinding) 10 | [![Platform](https://img.shields.io/cocoapods/p/SimpleTwoWayBinding.svg?style=flat)](http://cocoapods.org/pods/SimpleTwoWayBinding) 11 | 12 | ## The Need 13 | 14 | **MVVM**? why not *MVC* that Apple recommends? Android does *MVP* great right? How about the cool *VIPER* pattern? I believe [great efforts](https://medium.com/ios-os-x-development/ios-architecture-patterns-ecba4c38de52) have already been put to explain what each pattern brings to the table and so the idea here is not to add to the debate but merely build on top of the opinion I have already formed: _**MVVM is the way to go.**_ 15 | 16 | As a quick primer to what MVVM is, it is a design pattern whereby the *ViewModel* mediates between a data providing *Model* and *View* which displays the data provided like shown below: 17 | 18 | 19 | ![mvvm diag](https://github.com/manishkkatoch/SimpleTwoWayBindingIOS/blob/master/doc/diag.jpeg) 20 | 21 | 22 | in iOS, *View is essentially a ViewController* and ViewModel is an object (a structure) which provides exact data for the view to render. 23 | 24 | This provides a loosely coupled architecture which is maintainable ( very thin view controllers ) and testable (ViewModel abstracts out the UI and hence is easily testable) 25 | 26 | There is still a caveat though: _classic MVVM allows for single responsibility principle easily (and beautifully) in case of models as domain models. However, in case of anaemic models ( which is generally the case when you have well written REST APIs), one would also need another Mediator or Presenter which facilitates data and navigation flow._ 27 | 28 | Now, View Model has responsibility to update View as well as get updates from View regarding the changes made by the user. This can be achieved by minimum code using bi-directional data binding. 29 | But … _**iOS has no two way binding mechanism available out of the box!**_ 30 | 31 | Luckily we have reactive libraries like *RxSwift, RxCocoa* but they are too heavy considering two way binding is a very tiny part of the Reactive Programming paradigm. _**SimpleTwoWayBinding strives to provide just two way binding, in a simple unassuming way!**_ 32 | 33 | ## Example 34 | 35 | To run the example project, clone the repo, and run `pod install` from the Example directory first. 36 | 37 | ### Creating ViewModel 38 | 39 | ```swift 40 | import SimpleTwoWayBinding 41 | 42 | struct FormViewModel { 43 | let name: Observable = Observable() 44 | let companyName: Observable = Observable() 45 | let yearsOfExperience: Observable = Observable() 46 | let isCurrentEmployer: Observable = Observable(false) 47 | let approxSalary: Observable = Observable() 48 | let comments: Observable = Observable() 49 | } 50 | ``` 51 | The properties you want to be "bindable" to the View should be declared as Observable. 52 | 53 | ### Binding to ViewController 54 | ```swift 55 | class ViewController: UIViewController { 56 | 57 | @IBOutlet weak var nameField: UITextField! 58 | @IBOutlet weak var companyField: UITextField! 59 | @IBOutlet weak var isCurrentEmployerSwitch: UISwitch! 60 | @IBOutlet weak var yearsOfExperienceStepper: UIStepper! 61 | @IBOutlet weak var salaryRangeSlider: UISlider! 62 | @IBOutlet weak var selectedSalaryRangeLabel: UILabel! 63 | @IBOutlet weak var selectedYearsOfExperienceLabel: UILabel! 64 | 65 | var viewModel: FormViewModel! 66 | 67 | override func viewWillAppear(_ animated: Bool) { 68 | super.viewWillAppear(animated) 69 | self.navigationItem.title = "Survey Form" 70 | setupBindings() 71 | } 72 | 73 | func setupBindings() { 74 | nameField.bind(with: viewModel.name) 75 | companyField.bind(with: viewModel.companyName) 76 | isCurrentEmployerSwitch.bind(with: viewModel.isCurrentEmployer) 77 | yearsOfExperienceStepper.bind(with: viewModel.yearsOfExperience) 78 | salaryRangeSlider.bind(with: viewModel.approxSalary) 79 | 80 | selectedSalaryRangeLabel.observe(for: viewModel.approxSalary) { 81 | [unowned self](_) in 82 | self.selectedSalaryRangeLabel.text = 83 | self.viewModel.getSalaryString() 84 | } 85 | 86 | selectedYearsOfExperienceLabel.observe(for: viewModel.yearsOfExperience) { 87 | [unowned self](_) in 88 | self.selectedYearsOfExperienceLabel.text = 89 | self.viewModel.getExperienceString() 90 | } 91 | } 92 | } 93 | ``` 94 | The ```bind``` method on the UIControl orchestrates the two way binding with the Observable. That's all code that is needed to get the form working. See below screen shot. 95 | 96 | ![working sample](https://thumbs.gfycat.com/MealyThirdItaliangreyhound-size_restricted.gif) 97 | 98 | 99 | ## Installation 100 | 101 | SimpleTwoWayBinding is available through [CocoaPods](http://cocoapods.org). To install 102 | it, simply add the following line to your Podfile: 103 | 104 | ```ruby 105 | pod 'SimpleTwoWayBinding' 106 | ``` 107 | 108 | ## Author 109 | 110 | Manish Katoch, manish.katoch@gmail.com 111 | 112 | ## License 113 | 114 | SimpleTwoWayBinding is available under the MIT license. See the LICENSE file for more info. 115 | -------------------------------------------------------------------------------- /SimpleTwoWayBinding.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'SimpleTwoWayBinding' 3 | s.version = '0.0.3' 4 | s.summary = 'Ultra light weight and simple two way binding for iOS UIControls.' 5 | s.description = <<-DESC 6 | Ultra light weight and simple two way binding for UIControls. 7 | Written with love and hope in Swift 5. 8 | DESC 9 | 10 | s.homepage = 'https://github.com/manishkkatoch/SimpleTwoWayBindingIOS' 11 | s.license = { :type => 'MIT', :file => 'LICENSE' } 12 | s.author = { 'Manish Katoch' => 'manish.katoch@gmail.com' } 13 | s.source = { :git => 'https://github.com/manishkkatoch/SimpleTwoWayBindingIOS.git', :tag => s.version.to_s } 14 | s.ios.deployment_target = '8.0' 15 | 16 | s.source_files = 'Sources/**/*' 17 | s.frameworks = 'UIKit' 18 | s.swift_version = '5.0' 19 | end 20 | -------------------------------------------------------------------------------- /Sources/Bindable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Bindable.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | public protocol Bindable: NSObjectProtocol { 12 | associatedtype BindingType: Equatable 13 | func observingValue() -> BindingType? 14 | func updateValue(with value: BindingType) 15 | func bind(with observable: Observable) 16 | } 17 | 18 | fileprivate struct AssociatedKeys { 19 | static var binder: UInt8 = 0 20 | } 21 | 22 | extension Bindable where Self: NSObject { 23 | 24 | private var binder: Observable { 25 | get { 26 | guard let value = objc_getAssociatedObject(self, &AssociatedKeys.binder) as? Observable else { 27 | let newValue = Observable() 28 | objc_setAssociatedObject(self, &AssociatedKeys.binder, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) 29 | return newValue 30 | } 31 | return value 32 | } 33 | set(newValue) { 34 | objc_setAssociatedObject(self, &AssociatedKeys.binder, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) 35 | } 36 | } 37 | 38 | public func getBinderValue() -> BindingType? { 39 | return binder.value 40 | } 41 | 42 | public func setBinderValue(with value: BindingType?) { 43 | binder.value = value 44 | } 45 | 46 | public func register(for observable: Observable) { 47 | binder = observable 48 | } 49 | 50 | func valueChanged() { 51 | if binder.value != self.observingValue() { 52 | setBinderValue(with: self.observingValue()) 53 | } 54 | } 55 | 56 | public func bind(with observable: Observable) { 57 | if let _self = self as? UIControl { 58 | _self.addTarget(Selector, action: Selector{ [weak self] in self?.valueChanged() }, for: [.editingChanged, .valueChanged]) 59 | } 60 | self.binder = observable 61 | if let val = observable.value { 62 | self.updateValue(with: val) 63 | } 64 | self.observe(for: observable) { (value) in 65 | self.updateValue(with: value) 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Sources/BlockBasedSelector/BlockBasedSelector.h: -------------------------------------------------------------------------------- 1 | // BlockBasedSelector.h 2 | // 3 | // Created by Charlton Provatas on 11/2/17. 4 | // Copyright © 2017 CharltonProvatas. All rights reserved. 5 | // 6 | 7 | #import 8 | 9 | @interface BlockBasedSelector : NSObject 10 | 11 | @end 12 | 13 | typedef void (^OBJCBlock)(id foo); 14 | 15 | void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block); 16 | 17 | 18 | -------------------------------------------------------------------------------- /Sources/BlockBasedSelector/BlockBasedSelector.m: -------------------------------------------------------------------------------- 1 | // 2 | // BlockBasedSelector.m 3 | // 4 | // Created by Charlton Provatas on 11/2/17. 5 | // Copyright © 2017 CharltonProvatas. All rights reserved. 6 | // 7 | 8 | #import "BlockBasedSelector.h" 9 | #import 10 | 11 | @implementation BlockBasedSelector 12 | @end 13 | 14 | void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block) 15 | { 16 | IMP newImplementation = imp_implementationWithBlock(block); 17 | Method method = class_getInstanceMethod(class, newSelector); 18 | class_addMethod(class, newSelector, newImplementation, method_getTypeEncoding(method)); 19 | } 20 | -------------------------------------------------------------------------------- /Sources/BlockBasedSelector/BlockBasedSelector.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BlockBasedSelector.swift 3 | // 4 | // Created by Charlton Provatas on 11/2/17. 5 | // Copyright © 2017 CharltonProvatas. All rights reserved. 6 | 7 | import Foundation 8 | import UIKit 9 | 10 | func Selector(_ block: @escaping () -> Void) -> Selector { 11 | let selector = NSSelectorFromString("\(CACurrentMediaTime())") 12 | class_addMethodWithBlock(_Selector.self, selector) { (_) in block() } 13 | return selector 14 | } 15 | 16 | let Selector = _Selector.shared 17 | @objc class _Selector: NSObject { 18 | static let shared = _Selector() 19 | } 20 | -------------------------------------------------------------------------------- /Sources/NSObject+Observable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Observable.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // 7 | 8 | import Foundation 9 | 10 | extension NSObject { 11 | public func observe(for observable: Observable, with: @escaping (T) -> ()) { 12 | observable.bind { observable, value in 13 | DispatchQueue.main.async { 14 | with(value) 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/Observable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Observable.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // 7 | 8 | import Foundation 9 | 10 | public class Observable { 11 | public typealias Observer = (_ observable: Observable, ObservedType) -> Void 12 | 13 | private var observers: [Observer] 14 | 15 | public var value: ObservedType? { 16 | didSet { 17 | if let value = value { 18 | notifyObservers(value) 19 | } 20 | } 21 | } 22 | 23 | public init(_ value: ObservedType? = nil) { 24 | self.value = value 25 | observers = [] 26 | } 27 | 28 | public func bind(observer: @escaping Observer) { 29 | self.observers.append(observer) 30 | } 31 | 32 | private func notifyObservers(_ value: ObservedType) { 33 | self.observers.forEach { [unowned self](observer) in 34 | observer(self, value) 35 | } 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Sources/SimpleTwoWayBindings-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // SimpleTwoWayBindings-Bridging-Header.h 3 | // Pods 4 | // 5 | // Created by Manich Katoch on 11/26/17. 6 | // 7 | 8 | #import "BlockBasedSelector.h" 9 | -------------------------------------------------------------------------------- /Sources/UIControls+Bindable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIControls+Bindable.swift 3 | // SimpleTwoWayBinding 4 | // 5 | // Created by Manish Katoch on 11/26/17. 6 | // 7 | 8 | import Foundation 9 | 10 | extension UITextField : Bindable { 11 | public typealias BindingType = String 12 | 13 | public func observingValue() -> String? { 14 | return self.text 15 | } 16 | 17 | public func updateValue(with value: String) { 18 | if self.text != value { 19 | self.text = value 20 | } 21 | } 22 | } 23 | 24 | extension UISwitch : Bindable { 25 | public typealias BindingType = Bool 26 | 27 | public func observingValue() -> Bool? { 28 | return self.isOn 29 | } 30 | 31 | public func updateValue(with value: Bool) { 32 | self.isOn = value 33 | } 34 | } 35 | 36 | extension UISlider : Bindable { 37 | public typealias BindingType = Float 38 | 39 | public func observingValue() -> Float? { 40 | return self.value 41 | } 42 | 43 | public func updateValue(with value: Float) { 44 | self.value = value 45 | } 46 | } 47 | 48 | extension UIStepper : Bindable { 49 | public typealias BindingType = Double 50 | 51 | public func observingValue() -> Double? { 52 | return self.value 53 | } 54 | 55 | public func updateValue(with value: Double) { 56 | self.value = value 57 | } 58 | } 59 | 60 | extension UISegmentedControl : Bindable { 61 | public typealias BindingType = Int 62 | 63 | public func observingValue() -> Int? { 64 | return self.selectedSegmentIndex 65 | } 66 | 67 | public func updateValue(with value: Int) { 68 | self.selectedSegmentIndex = value 69 | } 70 | } 71 | 72 | public class BindableTextView: UITextView, Bindable, UITextViewDelegate { 73 | public typealias BindingType = String 74 | 75 | public func observingValue() -> String? { 76 | return self.text 77 | } 78 | 79 | public func updateValue(with value: String) { 80 | if self.text != value { 81 | self.text = value 82 | } 83 | } 84 | 85 | public func bind(with observable: Observable) { 86 | self.delegate = self 87 | self.register(for: observable) 88 | self.observe(for: observable) { [weak self] (value) in 89 | self?.updateValue(with: value) 90 | } 91 | } 92 | 93 | public func textViewDidChange(_ textView: UITextView) { 94 | self.valueChanged() 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /doc/diag.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manishkkatoch/SimpleTwoWayBindingIOS/24a62bcf5ad7e3ea7e53d80ea90bbdcf6b500933/doc/diag.jpeg --------------------------------------------------------------------------------