├── CombineCustomPublishers.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── dim8one.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── CombineCustomPublishers ├── Info.plist ├── Supporting Files │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── JustTableViewCell.swift │ └── SceneDelegate.swift ├── ViewController.swift └── 🚜 Publishers │ ├── ButtonPublisher.swift │ ├── SegmentControlPublisher.swift │ ├── SliderPublisher.swift │ ├── SwitchPublisher.swift │ ├── TableViewPublisher.swift │ └── TextFieldPubisher.swift └── README.md /CombineCustomPublishers.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4778593523F68DCD00870669 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778593423F68DCD00870669 /* AppDelegate.swift */; }; 11 | 4778593723F68DCD00870669 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778593623F68DCD00870669 /* SceneDelegate.swift */; }; 12 | 4778593923F68DCD00870669 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778593823F68DCD00870669 /* ViewController.swift */; }; 13 | 4778593C23F68DCD00870669 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4778593A23F68DCD00870669 /* Main.storyboard */; }; 14 | 4778593E23F68DCE00870669 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4778593D23F68DCE00870669 /* Assets.xcassets */; }; 15 | 4778594123F68DCE00870669 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4778593F23F68DCE00870669 /* LaunchScreen.storyboard */; }; 16 | 4778594923F6923D00870669 /* JustTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778594823F6923D00870669 /* JustTableViewCell.swift */; }; 17 | 4778594C23F6949300870669 /* ButtonPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778594B23F6949300870669 /* ButtonPublisher.swift */; }; 18 | 4778594E23F6983B00870669 /* TextFieldPubisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778594D23F6983B00870669 /* TextFieldPubisher.swift */; }; 19 | 4778595023F69D0000870669 /* SliderPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778594F23F69D0000870669 /* SliderPublisher.swift */; }; 20 | 4778595223F69E3D00870669 /* SegmentControlPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778595123F69E3D00870669 /* SegmentControlPublisher.swift */; }; 21 | 4778595623F6A33A00870669 /* SwitchPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778595523F6A33A00870669 /* SwitchPublisher.swift */; }; 22 | 4778595823F6A4A000870669 /* TableViewPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778595723F6A4A000870669 /* TableViewPublisher.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 4778593123F68DCD00870669 /* CombineCustomPublishers.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CombineCustomPublishers.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 4778593423F68DCD00870669 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 28 | 4778593623F68DCD00870669 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 29 | 4778593823F68DCD00870669 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 30 | 4778593B23F68DCD00870669 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 31 | 4778593D23F68DCE00870669 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 4778594023F68DCE00870669 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | 4778594223F68DCE00870669 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 4778594823F6923D00870669 /* JustTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustTableViewCell.swift; sourceTree = ""; }; 35 | 4778594B23F6949300870669 /* ButtonPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonPublisher.swift; sourceTree = ""; }; 36 | 4778594D23F6983B00870669 /* TextFieldPubisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldPubisher.swift; sourceTree = ""; }; 37 | 4778594F23F69D0000870669 /* SliderPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderPublisher.swift; sourceTree = ""; }; 38 | 4778595123F69E3D00870669 /* SegmentControlPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentControlPublisher.swift; sourceTree = ""; }; 39 | 4778595523F6A33A00870669 /* SwitchPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchPublisher.swift; sourceTree = ""; }; 40 | 4778595723F6A4A000870669 /* TableViewPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewPublisher.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 4778592E23F68DCD00870669 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 4778592823F68DCC00870669 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 4778593323F68DCD00870669 /* CombineCustomPublishers */, 58 | 4778593223F68DCD00870669 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | 4778593223F68DCD00870669 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 4778593123F68DCD00870669 /* CombineCustomPublishers.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | 4778593323F68DCD00870669 /* CombineCustomPublishers */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 47FFC53F23F6EB87002689A1 /* Supporting Files */, 74 | 4778594A23F6948000870669 /* 🚜 Publishers */, 75 | 4778593823F68DCD00870669 /* ViewController.swift */, 76 | 4778594223F68DCE00870669 /* Info.plist */, 77 | ); 78 | path = CombineCustomPublishers; 79 | sourceTree = ""; 80 | }; 81 | 4778594A23F6948000870669 /* 🚜 Publishers */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 4778594B23F6949300870669 /* ButtonPublisher.swift */, 85 | 4778594D23F6983B00870669 /* TextFieldPubisher.swift */, 86 | 4778594F23F69D0000870669 /* SliderPublisher.swift */, 87 | 4778595123F69E3D00870669 /* SegmentControlPublisher.swift */, 88 | 4778595523F6A33A00870669 /* SwitchPublisher.swift */, 89 | 4778595723F6A4A000870669 /* TableViewPublisher.swift */, 90 | ); 91 | path = "🚜 Publishers"; 92 | sourceTree = ""; 93 | }; 94 | 47FFC53F23F6EB87002689A1 /* Supporting Files */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 4778594823F6923D00870669 /* JustTableViewCell.swift */, 98 | 4778593D23F68DCE00870669 /* Assets.xcassets */, 99 | 4778593F23F68DCE00870669 /* LaunchScreen.storyboard */, 100 | 4778593A23F68DCD00870669 /* Main.storyboard */, 101 | 4778593423F68DCD00870669 /* AppDelegate.swift */, 102 | 4778593623F68DCD00870669 /* SceneDelegate.swift */, 103 | ); 104 | path = "Supporting Files"; 105 | sourceTree = ""; 106 | }; 107 | /* End PBXGroup section */ 108 | 109 | /* Begin PBXNativeTarget section */ 110 | 4778593023F68DCD00870669 /* CombineCustomPublishers */ = { 111 | isa = PBXNativeTarget; 112 | buildConfigurationList = 4778594523F68DCE00870669 /* Build configuration list for PBXNativeTarget "CombineCustomPublishers" */; 113 | buildPhases = ( 114 | 4778592D23F68DCD00870669 /* Sources */, 115 | 4778592E23F68DCD00870669 /* Frameworks */, 116 | 4778592F23F68DCD00870669 /* Resources */, 117 | ); 118 | buildRules = ( 119 | ); 120 | dependencies = ( 121 | ); 122 | name = CombineCustomPublishers; 123 | productName = CombineCustomPublishers; 124 | productReference = 4778593123F68DCD00870669 /* CombineCustomPublishers.app */; 125 | productType = "com.apple.product-type.application"; 126 | }; 127 | /* End PBXNativeTarget section */ 128 | 129 | /* Begin PBXProject section */ 130 | 4778592923F68DCC00870669 /* Project object */ = { 131 | isa = PBXProject; 132 | attributes = { 133 | LastSwiftUpdateCheck = 1130; 134 | LastUpgradeCheck = 1130; 135 | ORGANIZATIONNAME = "Dmitry Lupich"; 136 | TargetAttributes = { 137 | 4778593023F68DCD00870669 = { 138 | CreatedOnToolsVersion = 11.3; 139 | }; 140 | }; 141 | }; 142 | buildConfigurationList = 4778592C23F68DCC00870669 /* Build configuration list for PBXProject "CombineCustomPublishers" */; 143 | compatibilityVersion = "Xcode 9.3"; 144 | developmentRegion = en; 145 | hasScannedForEncodings = 0; 146 | knownRegions = ( 147 | en, 148 | Base, 149 | ); 150 | mainGroup = 4778592823F68DCC00870669; 151 | productRefGroup = 4778593223F68DCD00870669 /* Products */; 152 | projectDirPath = ""; 153 | projectRoot = ""; 154 | targets = ( 155 | 4778593023F68DCD00870669 /* CombineCustomPublishers */, 156 | ); 157 | }; 158 | /* End PBXProject section */ 159 | 160 | /* Begin PBXResourcesBuildPhase section */ 161 | 4778592F23F68DCD00870669 /* Resources */ = { 162 | isa = PBXResourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 4778594123F68DCE00870669 /* LaunchScreen.storyboard in Resources */, 166 | 4778593E23F68DCE00870669 /* Assets.xcassets in Resources */, 167 | 4778593C23F68DCD00870669 /* Main.storyboard in Resources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXSourcesBuildPhase section */ 174 | 4778592D23F68DCD00870669 /* Sources */ = { 175 | isa = PBXSourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | 4778595023F69D0000870669 /* SliderPublisher.swift in Sources */, 179 | 4778593923F68DCD00870669 /* ViewController.swift in Sources */, 180 | 4778595223F69E3D00870669 /* SegmentControlPublisher.swift in Sources */, 181 | 4778593523F68DCD00870669 /* AppDelegate.swift in Sources */, 182 | 4778593723F68DCD00870669 /* SceneDelegate.swift in Sources */, 183 | 4778594923F6923D00870669 /* JustTableViewCell.swift in Sources */, 184 | 4778594C23F6949300870669 /* ButtonPublisher.swift in Sources */, 185 | 4778595623F6A33A00870669 /* SwitchPublisher.swift in Sources */, 186 | 4778595823F6A4A000870669 /* TableViewPublisher.swift in Sources */, 187 | 4778594E23F6983B00870669 /* TextFieldPubisher.swift in Sources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXSourcesBuildPhase section */ 192 | 193 | /* Begin PBXVariantGroup section */ 194 | 4778593A23F68DCD00870669 /* Main.storyboard */ = { 195 | isa = PBXVariantGroup; 196 | children = ( 197 | 4778593B23F68DCD00870669 /* Base */, 198 | ); 199 | name = Main.storyboard; 200 | sourceTree = ""; 201 | }; 202 | 4778593F23F68DCE00870669 /* LaunchScreen.storyboard */ = { 203 | isa = PBXVariantGroup; 204 | children = ( 205 | 4778594023F68DCE00870669 /* Base */, 206 | ); 207 | name = LaunchScreen.storyboard; 208 | sourceTree = ""; 209 | }; 210 | /* End PBXVariantGroup section */ 211 | 212 | /* Begin XCBuildConfiguration section */ 213 | 4778594323F68DCE00870669 /* Debug */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_ANALYZER_NONNULL = YES; 218 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 219 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 220 | CLANG_CXX_LIBRARY = "libc++"; 221 | CLANG_ENABLE_MODULES = YES; 222 | CLANG_ENABLE_OBJC_ARC = YES; 223 | CLANG_ENABLE_OBJC_WEAK = YES; 224 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 225 | CLANG_WARN_BOOL_CONVERSION = YES; 226 | CLANG_WARN_COMMA = YES; 227 | CLANG_WARN_CONSTANT_CONVERSION = YES; 228 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 231 | CLANG_WARN_EMPTY_BODY = YES; 232 | CLANG_WARN_ENUM_CONVERSION = YES; 233 | CLANG_WARN_INFINITE_RECURSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | COPY_PHASE_STRIP = NO; 246 | DEBUG_INFORMATION_FORMAT = dwarf; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | ENABLE_TESTABILITY = YES; 249 | GCC_C_LANGUAGE_STANDARD = gnu11; 250 | GCC_DYNAMIC_NO_PIC = NO; 251 | GCC_NO_COMMON_BLOCKS = YES; 252 | GCC_OPTIMIZATION_LEVEL = 0; 253 | GCC_PREPROCESSOR_DEFINITIONS = ( 254 | "DEBUG=1", 255 | "$(inherited)", 256 | ); 257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 259 | GCC_WARN_UNDECLARED_SELECTOR = YES; 260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 261 | GCC_WARN_UNUSED_FUNCTION = YES; 262 | GCC_WARN_UNUSED_VARIABLE = YES; 263 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 264 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 265 | MTL_FAST_MATH = YES; 266 | ONLY_ACTIVE_ARCH = YES; 267 | SDKROOT = iphoneos; 268 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 269 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 270 | }; 271 | name = Debug; 272 | }; 273 | 4778594423F68DCE00870669 /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ALWAYS_SEARCH_USER_PATHS = NO; 277 | CLANG_ANALYZER_NONNULL = YES; 278 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 279 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 280 | CLANG_CXX_LIBRARY = "libc++"; 281 | CLANG_ENABLE_MODULES = YES; 282 | CLANG_ENABLE_OBJC_ARC = YES; 283 | CLANG_ENABLE_OBJC_WEAK = YES; 284 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 285 | CLANG_WARN_BOOL_CONVERSION = YES; 286 | CLANG_WARN_COMMA = YES; 287 | CLANG_WARN_CONSTANT_CONVERSION = YES; 288 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INFINITE_RECURSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 297 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 298 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 299 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 300 | CLANG_WARN_STRICT_PROTOTYPES = YES; 301 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 302 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 303 | CLANG_WARN_UNREACHABLE_CODE = YES; 304 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 305 | COPY_PHASE_STRIP = NO; 306 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 307 | ENABLE_NS_ASSERTIONS = NO; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | GCC_C_LANGUAGE_STANDARD = gnu11; 310 | GCC_NO_COMMON_BLOCKS = YES; 311 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 312 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 313 | GCC_WARN_UNDECLARED_SELECTOR = YES; 314 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 315 | GCC_WARN_UNUSED_FUNCTION = YES; 316 | GCC_WARN_UNUSED_VARIABLE = YES; 317 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 318 | MTL_ENABLE_DEBUG_INFO = NO; 319 | MTL_FAST_MATH = YES; 320 | SDKROOT = iphoneos; 321 | SWIFT_COMPILATION_MODE = wholemodule; 322 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 323 | VALIDATE_PRODUCT = YES; 324 | }; 325 | name = Release; 326 | }; 327 | 4778594623F68DCE00870669 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | CODE_SIGN_STYLE = Automatic; 332 | DEVELOPMENT_TEAM = R2AYB7993E; 333 | INFOPLIST_FILE = CombineCustomPublishers/Info.plist; 334 | LD_RUNPATH_SEARCH_PATHS = ( 335 | "$(inherited)", 336 | "@executable_path/Frameworks", 337 | ); 338 | PRODUCT_BUNDLE_IDENTIFIER = DmitryLupich.CombineCustomPublishers; 339 | PRODUCT_NAME = "$(TARGET_NAME)"; 340 | SWIFT_VERSION = 5.0; 341 | TARGETED_DEVICE_FAMILY = "1,2"; 342 | }; 343 | name = Debug; 344 | }; 345 | 4778594723F68DCE00870669 /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | CODE_SIGN_STYLE = Automatic; 350 | DEVELOPMENT_TEAM = R2AYB7993E; 351 | INFOPLIST_FILE = CombineCustomPublishers/Info.plist; 352 | LD_RUNPATH_SEARCH_PATHS = ( 353 | "$(inherited)", 354 | "@executable_path/Frameworks", 355 | ); 356 | PRODUCT_BUNDLE_IDENTIFIER = DmitryLupich.CombineCustomPublishers; 357 | PRODUCT_NAME = "$(TARGET_NAME)"; 358 | SWIFT_VERSION = 5.0; 359 | TARGETED_DEVICE_FAMILY = "1,2"; 360 | }; 361 | name = Release; 362 | }; 363 | /* End XCBuildConfiguration section */ 364 | 365 | /* Begin XCConfigurationList section */ 366 | 4778592C23F68DCC00870669 /* Build configuration list for PBXProject "CombineCustomPublishers" */ = { 367 | isa = XCConfigurationList; 368 | buildConfigurations = ( 369 | 4778594323F68DCE00870669 /* Debug */, 370 | 4778594423F68DCE00870669 /* Release */, 371 | ); 372 | defaultConfigurationIsVisible = 0; 373 | defaultConfigurationName = Release; 374 | }; 375 | 4778594523F68DCE00870669 /* Build configuration list for PBXNativeTarget "CombineCustomPublishers" */ = { 376 | isa = XCConfigurationList; 377 | buildConfigurations = ( 378 | 4778594623F68DCE00870669 /* Debug */, 379 | 4778594723F68DCE00870669 /* Release */, 380 | ); 381 | defaultConfigurationIsVisible = 0; 382 | defaultConfigurationName = Release; 383 | }; 384 | /* End XCConfigurationList section */ 385 | }; 386 | rootObject = 4778592923F68DCC00870669 /* Project object */; 387 | } 388 | -------------------------------------------------------------------------------- /CombineCustomPublishers.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CombineCustomPublishers.xcodeproj/xcuserdata/dim8one.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CombineCustomPublishers.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/Assets.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" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/Base.lproj/LaunchScreen.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 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 29 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 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 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/JustTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // JustTableViewCell.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class JustTableViewCell: UITableViewCell { 12 | override var reuseIdentifier: String? { 13 | return "JustTableViewCell" 14 | } 15 | } 16 | 17 | extension JustTableViewCell { 18 | func configure(with title: String) { 19 | self.textLabel?.text = title 20 | self.backgroundColor = .clear 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CombineCustomPublishers/Supporting Files/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 18 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 19 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 20 | guard let _ = (scene as? UIWindowScene) else { return } 21 | } 22 | 23 | func sceneDidDisconnect(_ scene: UIScene) { 24 | // Called as the scene is being released by the system. 25 | // This occurs shortly after the scene enters the background, or when its session is discarded. 26 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 27 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 28 | } 29 | 30 | func sceneDidBecomeActive(_ scene: UIScene) { 31 | // Called when the scene has moved from an inactive state to an active state. 32 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 33 | } 34 | 35 | func sceneWillResignActive(_ scene: UIScene) { 36 | // Called when the scene will move from an active state to an inactive state. 37 | // This may occur due to temporary interruptions (ex. an incoming phone call). 38 | } 39 | 40 | func sceneWillEnterForeground(_ scene: UIScene) { 41 | // Called as the scene transitions from the background to the foreground. 42 | // Use this method to undo the changes made on entering the background. 43 | } 44 | 45 | func sceneDidEnterBackground(_ scene: UIScene) { 46 | // Called as the scene transitions from the foreground to the background. 47 | // Use this method to save data, release shared resources, and store enough scene-specific state information 48 | // to restore the scene back to its current state. 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /CombineCustomPublishers/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Combine 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet private weak var outputLabel: UILabel! 15 | @IBOutlet private weak var justButton: UIButton! 16 | @IBOutlet private weak var justTextField: UITextField! 17 | @IBOutlet private weak var justSlider: UISlider! 18 | @IBOutlet private weak var justSegmentControl: UISegmentedControl! 19 | @IBOutlet private weak var justSpinner: UIActivityIndicatorView! 20 | @IBOutlet private weak var spinnerButton: UIButton! 21 | @IBOutlet private weak var justSwitch: UISwitch! 22 | @IBOutlet private weak var justTableView: UITableView! 23 | 24 | private var cancelBag = Set() 25 | private let cellModels = Array(0...99).map(String.init) 26 | private let cellID = "JustTableViewCell" 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | setupView() 31 | setupStreams() 32 | } 33 | } 34 | 35 | extension ViewController { 36 | private func setupView() { 37 | setupTableView() 38 | } 39 | 40 | private func setupStreams() { 41 | let justTap = justButton.publisher.share() 42 | 43 | justTap 44 | .map { "Button tap".consoleLog("🆗") } 45 | .assign(to: \UILabel.text, on: outputLabel) 46 | .store(in: &cancelBag) 47 | 48 | justTap.sink { _ in 49 | self.view.endEditing(true) 50 | }.store(in: &cancelBag) 51 | 52 | justTextField.publisher 53 | .map { $0.consoleLog("🔠") } 54 | .assign(to: \UILabel.text, on: outputLabel) 55 | .store(in: &cancelBag) 56 | 57 | justSlider.publisher 58 | .map { String(describing: $0).consoleLog("↔️") } 59 | .assign(to: \UILabel.text, on: outputLabel) 60 | .store(in: &cancelBag) 61 | 62 | justSegmentControl.publisher 63 | .map { $0.consoleLog("🔢") } 64 | .assign(to: \UILabel.text, on: outputLabel) 65 | .store(in: &cancelBag) 66 | 67 | spinnerButton.publisher 68 | .scan(false) { (flag, _) -> Bool in 69 | return !flag 70 | }.sink(receiveValue: { flag in 71 | flag ? self.justSpinner.startAnimating() : self.justSpinner.stopAnimating() 72 | self.outputLabel.text = flag ? "▶️ Run Spinner" : "⏸ Stop Spinner" 73 | }).store(in: &cancelBag) 74 | 75 | justSwitch.publisher 76 | .sink(receiveValue: { isOn in 77 | self.outputLabel.text = isOn ? "1️⃣ Switch is On" : "0️⃣ Switch is Off" 78 | }).store(in: &cancelBag) 79 | 80 | justTableView.publisher 81 | .map(mapToSrting(_:)) 82 | .assign(to: \UILabel.text, on: outputLabel) 83 | .store(in: &cancelBag) 84 | } 85 | 86 | private func setupTableView() { 87 | justTableView.delegate = self 88 | justTableView.dataSource = self 89 | justTableView.register( 90 | JustTableViewCell.self, 91 | forCellReuseIdentifier: cellID 92 | ) 93 | } 94 | 95 | private func mapToSrting(_ value: TableValue) -> String { 96 | switch value { 97 | case .indexPath(let indexPath): 98 | return "Row \(indexPath.row) | Section \(indexPath.section)".consoleLog("ℹ️") 99 | case .offSet(let offSet): 100 | return "OffSet \(offSet)".consoleLog("↕️") 101 | } 102 | } 103 | } 104 | 105 | extension ViewController: UITableViewDelegate, UITableViewDataSource { 106 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 107 | cellModels.count 108 | } 109 | 110 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 111 | guard 112 | let cell = tableView 113 | .dequeueReusableCell( 114 | withIdentifier: cellID, 115 | for: indexPath 116 | ) as? JustTableViewCell 117 | else { return UITableViewCell() } 118 | cell.configure(with: cellModels[indexPath.row]) 119 | return cell 120 | } 121 | } 122 | 123 | extension String { 124 | func consoleLog(_ emoji: String) -> String { 125 | [emoji, self].joined(separator:" ") 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/ButtonPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonPublisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | extension UIButton { 14 | var publisher: Publishers.ButtonPublisher { 15 | return Publishers.ButtonPublisher(button: self) 16 | } 17 | } 18 | 19 | extension Publishers { 20 | struct ButtonPublisher: Publisher { 21 | typealias Output = Void 22 | typealias Failure = Never 23 | 24 | private let button: UIButton 25 | 26 | init(button: UIButton) { self.button = button } 27 | 28 | func receive(subscriber: S) where S : Subscriber, Publishers.ButtonPublisher.Failure == S.Failure, Publishers.ButtonPublisher.Output == S.Input { 29 | let subscription = ButtonSubscription(subscriber: subscriber, button: button) 30 | subscriber.receive(subscription: subscription) 31 | } 32 | } 33 | 34 | class ButtonSubscription: Subscription where S.Input == Void, S.Failure == Never { 35 | 36 | private var subscriber: S? 37 | private weak var button: UIButton? 38 | 39 | init(subscriber: S, button: UIButton) { 40 | self.subscriber = subscriber 41 | self.button = button 42 | subscribe() 43 | } 44 | 45 | func request(_ demand: Subscribers.Demand) { } 46 | 47 | func cancel() { 48 | subscriber = nil 49 | button = nil 50 | } 51 | 52 | private func subscribe() { 53 | button?.addTarget(self, 54 | action: #selector(tap(_:)), 55 | for: .touchUpInside) 56 | } 57 | 58 | @objc private func tap(_ sender: UIButton) { 59 | _ = subscriber?.receive(()) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/SegmentControlPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SegmentControlPublisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | extension UISegmentedControl { 14 | var publisher: Publishers.SegmentedControlPublisher { 15 | return Publishers.SegmentedControlPublisher(segmentedControl: self) 16 | } 17 | } 18 | 19 | extension Publishers { 20 | struct SegmentedControlPublisher: Publisher { 21 | typealias Output = String 22 | typealias Failure = Never 23 | 24 | private let segmentedControl: UISegmentedControl 25 | 26 | init(segmentedControl: UISegmentedControl) { self.segmentedControl = segmentedControl } 27 | 28 | func receive(subscriber: S) where S : Subscriber, Publishers.SegmentedControlPublisher.Failure == S.Failure, Publishers.SegmentedControlPublisher.Output == S.Input { 29 | let subscription = SegmentedControlSubscription(subscriber: subscriber, 30 | segmentedControl: segmentedControl) 31 | subscriber.receive(subscription: subscription) 32 | } 33 | } 34 | 35 | class SegmentedControlSubscription: Subscription where S.Input == String, S.Failure == Never { 36 | 37 | private var subscriber: S? 38 | private weak var segmentedControl: UISegmentedControl? 39 | 40 | init(subscriber: S, segmentedControl: UISegmentedControl) { 41 | self.subscriber = subscriber 42 | self.segmentedControl = segmentedControl 43 | subscribe() 44 | } 45 | 46 | func request(_ demand: Subscribers.Demand) { } 47 | 48 | func cancel() { 49 | subscriber = nil 50 | segmentedControl = nil 51 | } 52 | 53 | private func subscribe() { 54 | segmentedControl?.addTarget(self, 55 | action: #selector(valueChanged(_:)), 56 | for: .valueChanged) 57 | } 58 | 59 | @objc private func valueChanged(_ sender: UISegmentedControl) { 60 | _ = subscriber?.receive(sender.titleForSegment(at: sender.selectedSegmentIndex) ?? "") 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/SliderPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SliderPublisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | extension UISlider { 14 | var publisher: Publishers.SliderPublisher { 15 | return Publishers.SliderPublisher(slider: self) 16 | } 17 | } 18 | 19 | extension Publishers { 20 | struct SliderPublisher: Publisher { 21 | typealias Output = CGFloat 22 | typealias Failure = Never 23 | 24 | private let slider: UISlider 25 | 26 | init(slider: UISlider) { self.slider = slider } 27 | 28 | func receive(subscriber: S) where S : Subscriber, Publishers.SliderPublisher.Failure == S.Failure, Publishers.SliderPublisher.Output == S.Input { 29 | let subscription = SliderSubscription(subscriber: subscriber, slider: slider) 30 | subscriber.receive(subscription: subscription) 31 | } 32 | } 33 | 34 | class SliderSubscription: Subscription where S.Input == CGFloat, S.Failure == Never { 35 | 36 | private var subscriber: S? 37 | private weak var slider: UISlider? 38 | 39 | init(subscriber: S, slider: UISlider) { 40 | self.subscriber = subscriber 41 | self.slider = slider 42 | subscribe() 43 | } 44 | 45 | func request(_ demand: Subscribers.Demand) { } 46 | 47 | func cancel() { 48 | subscriber = nil 49 | slider = nil 50 | } 51 | 52 | private func subscribe() { 53 | slider?.addTarget(self, 54 | action: #selector(valueChanged(_:)), 55 | for: .valueChanged) 56 | } 57 | 58 | @objc private func valueChanged(_ sender: UISlider) { 59 | _ = subscriber?.receive(CGFloat(sender.value)) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/SwitchPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwitchPublisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | extension UISwitch { 14 | var publisher: Publishers.SwitchPublisher { 15 | return Publishers.SwitchPublisher(switcher: self) 16 | } 17 | } 18 | 19 | extension Publishers { 20 | struct SwitchPublisher: Publisher { 21 | typealias Output = Bool 22 | typealias Failure = Never 23 | 24 | private let switcher: UISwitch 25 | 26 | init(switcher: UISwitch) { self.switcher = switcher } 27 | 28 | func receive(subscriber: S) where S : Subscriber, Publishers.SwitchPublisher.Failure == S.Failure, Publishers.SwitchPublisher.Output == S.Input { 29 | let subscription = SwitchSubscription(subscriber: subscriber, switcher: switcher) 30 | subscriber.receive(subscription: subscription) 31 | } 32 | } 33 | 34 | class SwitchSubscription: Subscription where S.Input == Bool, S.Failure == Never { 35 | 36 | private var subscriber: S? 37 | private weak var switcher: UISwitch? 38 | 39 | init(subscriber: S, switcher: UISwitch) { 40 | self.subscriber = subscriber 41 | self.switcher = switcher 42 | subscribe() 43 | } 44 | 45 | func request(_ demand: Subscribers.Demand) { } 46 | 47 | func cancel() { 48 | subscriber = nil 49 | switcher = nil 50 | } 51 | 52 | private func subscribe() { 53 | switcher?.addTarget(self, 54 | action: #selector(tap(_:)), 55 | for: .valueChanged) 56 | } 57 | 58 | @objc private func tap(_ sender: UISwitch) { 59 | _ = subscriber?.receive(sender.isOn) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/TableViewPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewPublisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | enum TableValue { 14 | case indexPath(IndexPath) 15 | case offSet(CGFloat) 16 | } 17 | 18 | extension UITableView { 19 | var publisher: Publishers.TableViewPublisher { 20 | return Publishers.TableViewPublisher(tableView: self) 21 | } 22 | } 23 | 24 | extension Publishers { 25 | struct TableViewPublisher: Publisher { 26 | typealias Output = TableValue 27 | typealias Failure = Never 28 | 29 | private let tableView: UITableView 30 | 31 | init(tableView: UITableView) { self.tableView = tableView } 32 | 33 | func receive(subscriber: S) where S : Subscriber, Publishers.TableViewPublisher.Failure == S.Failure, Publishers.TableViewPublisher.Output == S.Input { 34 | let subscription = TableViewSubscription(subscriber: subscriber, tableView: tableView) 35 | subscriber.receive(subscription: subscription) 36 | } 37 | } 38 | 39 | class TableViewSubscription: Subscription where S.Input == TableValue, S.Failure == Never { 40 | 41 | private var subscriber: S? 42 | private weak var tableView: UITableView? 43 | private let delegate = TableViewDelegate() 44 | 45 | init(subscriber: S, tableView: UITableView) { 46 | self.subscriber = subscriber 47 | self.tableView = tableView 48 | subscribe() 49 | } 50 | 51 | func request(_ demand: Subscribers.Demand) { } 52 | 53 | func cancel() { 54 | subscriber = nil 55 | tableView = nil 56 | } 57 | 58 | private func subscribe() { 59 | tableView?.delegate = delegate 60 | delegate.selected = { [weak self] indexPath in 61 | _ = self?.subscriber?.receive(indexPath) 62 | } 63 | } 64 | } 65 | 66 | class TableViewDelegate: NSObject, UITableViewDelegate { 67 | 68 | var selected: ((TableValue) -> Void)? 69 | 70 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 71 | selected?(.indexPath(indexPath)) 72 | } 73 | 74 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 75 | selected?(.offSet(scrollView.contentOffset.y)) 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /CombineCustomPublishers/🚜 Publishers/TextFieldPubisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextFieldPubisher.swift 3 | // CombineCustomPublishers 4 | // 5 | // Created by Dmitriy Lupych on 14.02.2020. 6 | // Copyright © 2020 Dmitry Lupich. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | import UIKit 12 | 13 | extension UITextField { 14 | var publisher: Publishers.TextFieldPublisher { 15 | return Publishers.TextFieldPublisher(textField: self) 16 | } 17 | } 18 | 19 | extension Publishers { 20 | struct TextFieldPublisher: Publisher { 21 | typealias Output = String 22 | typealias Failure = Never 23 | 24 | private let textField: UITextField 25 | 26 | init(textField: UITextField) { self.textField = textField } 27 | 28 | func receive(subscriber: S) where S : Subscriber, Publishers.TextFieldPublisher.Failure == S.Failure, Publishers.TextFieldPublisher.Output == S.Input { 29 | let subscription = TextFieldSubscription(subscriber: subscriber, textField: textField) 30 | subscriber.receive(subscription: subscription) 31 | } 32 | } 33 | 34 | class TextFieldSubscription: Subscription where S.Input == String, S.Failure == Never { 35 | 36 | private var subscriber: S? 37 | private weak var textField: UITextField? 38 | 39 | init(subscriber: S, textField: UITextField) { 40 | self.subscriber = subscriber 41 | self.textField = textField 42 | subscribe() 43 | } 44 | 45 | func request(_ demand: Subscribers.Demand) { } 46 | 47 | func cancel() { 48 | subscriber = nil 49 | textField = nil 50 | } 51 | 52 | private func subscribe() { 53 | textField?.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged) 54 | } 55 | 56 | @objc private func textFieldDidChange(_ textField: UITextField) { 57 | _ = subscriber?.receive(textField.text ?? "") 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Combine-UIKit 2 | 3 | ![Demo: using Combine publishers with UIKit controls](https://media.giphy.com/media/lMfaeDpAeOdPvwTu09/giphy.gif) 4 | 5 | How to create custom publishers for such elements of UIKit framework like: 6 | - buttons 7 | - sliders 8 | - tableViews 9 | - textFields 10 | - switches 11 | - and others 12 | --------------------------------------------------------------------------------