├── Cycler.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── rui.peres.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ ├── Cycler.xcscheme │ │ └── Example.xcscheme └── xcuserdata │ ├── anders.ha.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ └── xcschememanagement.plist │ └── rui.peres.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── Cycler ├── Info.plist └── Sources │ ├── BoundView.swift │ ├── Feedback.swift │ ├── FeedbackLoop.swift │ └── ViewModel.swift ├── Example ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── CounterView.swift ├── CounterViewModel.swift ├── Info.plist ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── SceneDelegate.swift ├── Package.swift ├── README.md └── dataflow.png /Cycler.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 65E47D6A22ADB1E600A83B79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D6922ADB1E600A83B79 /* AppDelegate.swift */; }; 11 | 65E47D6C22ADB1E600A83B79 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D6B22ADB1E600A83B79 /* SceneDelegate.swift */; }; 12 | 65E47D6E22ADB1E600A83B79 /* CounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D6D22ADB1E600A83B79 /* CounterView.swift */; }; 13 | 65E47D7022ADB1E800A83B79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65E47D6F22ADB1E800A83B79 /* Assets.xcassets */; }; 14 | 65E47D7322ADB1E800A83B79 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65E47D7222ADB1E800A83B79 /* Preview Assets.xcassets */; }; 15 | 65E47D7622ADB1E800A83B79 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65E47D7422ADB1E800A83B79 /* LaunchScreen.storyboard */; }; 16 | 65E47D8222ADBD4E00A83B79 /* CounterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D8122ADBD4E00A83B79 /* CounterViewModel.swift */; }; 17 | B2C4433F2338BE05006D7C3B /* Cycler.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2C443382338BE05006D7C3B /* Cycler.framework */; }; 18 | B2C443402338BE05006D7C3B /* Cycler.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B2C443382338BE05006D7C3B /* Cycler.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 19 | B2C443462338BF32006D7C3B /* BoundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D8B22ADF2F000A83B79 /* BoundView.swift */; }; 20 | B2C443472338BF32006D7C3B /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D8922ADEE7100A83B79 /* ViewModel.swift */; }; 21 | B2C443482338BF32006D7C3B /* FeedbackLoop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D8722ADC54B00A83B79 /* FeedbackLoop.swift */; }; 22 | B2C443492338BF32006D7C3B /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E47D9022AEE16600A83B79 /* Feedback.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | B2C4433D2338BE05006D7C3B /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = 65E47D5E22ADB1E600A83B79 /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = B2C443372338BE05006D7C3B; 31 | remoteInfo = Cycler; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXCopyFilesBuildPhase section */ 36 | B2C443442338BE05006D7C3B /* Embed Frameworks */ = { 37 | isa = PBXCopyFilesBuildPhase; 38 | buildActionMask = 2147483647; 39 | dstPath = ""; 40 | dstSubfolderSpec = 10; 41 | files = ( 42 | B2C443402338BE05006D7C3B /* Cycler.framework in Embed Frameworks */, 43 | ); 44 | name = "Embed Frameworks"; 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXCopyFilesBuildPhase section */ 48 | 49 | /* Begin PBXFileReference section */ 50 | 65E47D6622ADB1E600A83B79 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 65E47D6922ADB1E600A83B79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52 | 65E47D6B22ADB1E600A83B79 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 53 | 65E47D6D22ADB1E600A83B79 /* CounterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterView.swift; sourceTree = ""; }; 54 | 65E47D6F22ADB1E800A83B79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | 65E47D7222ADB1E800A83B79 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 56 | 65E47D7522ADB1E800A83B79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 57 | 65E47D7722ADB1E800A83B79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | 65E47D8122ADBD4E00A83B79 /* CounterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterViewModel.swift; sourceTree = ""; }; 59 | 65E47D8722ADC54B00A83B79 /* FeedbackLoop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackLoop.swift; sourceTree = ""; }; 60 | 65E47D8922ADEE7100A83B79 /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = ""; }; 61 | 65E47D8B22ADF2F000A83B79 /* BoundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoundView.swift; sourceTree = ""; }; 62 | 65E47D8F22AEB40700A83B79 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 63 | 65E47D9022AEE16600A83B79 /* Feedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Feedback.swift; sourceTree = ""; }; 64 | B2C443382338BE05006D7C3B /* Cycler.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cycler.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | B2C4433B2338BE05006D7C3B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 66 | /* End PBXFileReference section */ 67 | 68 | /* Begin PBXFrameworksBuildPhase section */ 69 | 65E47D6322ADB1E600A83B79 /* Frameworks */ = { 70 | isa = PBXFrameworksBuildPhase; 71 | buildActionMask = 2147483647; 72 | files = ( 73 | B2C4433F2338BE05006D7C3B /* Cycler.framework in Frameworks */, 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | B2C443352338BE05006D7C3B /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | 65E47D5D22ADB1E600A83B79 = { 88 | isa = PBXGroup; 89 | children = ( 90 | 65E47D8F22AEB40700A83B79 /* README.md */, 91 | 65E47D6822ADB1E600A83B79 /* Example */, 92 | B2C443392338BE05006D7C3B /* Cycler */, 93 | 65E47D6722ADB1E600A83B79 /* Products */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | 65E47D6722ADB1E600A83B79 /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 65E47D6622ADB1E600A83B79 /* Example.app */, 101 | B2C443382338BE05006D7C3B /* Cycler.framework */, 102 | ); 103 | name = Products; 104 | sourceTree = ""; 105 | }; 106 | 65E47D6822ADB1E600A83B79 /* Example */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 65E47D6922ADB1E600A83B79 /* AppDelegate.swift */, 110 | 65E47D6B22ADB1E600A83B79 /* SceneDelegate.swift */, 111 | 65E47D6D22ADB1E600A83B79 /* CounterView.swift */, 112 | 65E47D8122ADBD4E00A83B79 /* CounterViewModel.swift */, 113 | 65E47D6F22ADB1E800A83B79 /* Assets.xcassets */, 114 | 65E47D7422ADB1E800A83B79 /* LaunchScreen.storyboard */, 115 | 65E47D7722ADB1E800A83B79 /* Info.plist */, 116 | 65E47D7122ADB1E800A83B79 /* Preview Content */, 117 | ); 118 | path = Example; 119 | sourceTree = ""; 120 | }; 121 | 65E47D7122ADB1E800A83B79 /* Preview Content */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 65E47D7222ADB1E800A83B79 /* Preview Assets.xcassets */, 125 | ); 126 | path = "Preview Content"; 127 | sourceTree = ""; 128 | }; 129 | B2C443392338BE05006D7C3B /* Cycler */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | B2C443452338BEA2006D7C3B /* Sources */, 133 | B2C4433B2338BE05006D7C3B /* Info.plist */, 134 | ); 135 | path = Cycler; 136 | sourceTree = ""; 137 | }; 138 | B2C443452338BEA2006D7C3B /* Sources */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 65E47D8B22ADF2F000A83B79 /* BoundView.swift */, 142 | 65E47D8922ADEE7100A83B79 /* ViewModel.swift */, 143 | 65E47D8722ADC54B00A83B79 /* FeedbackLoop.swift */, 144 | 65E47D9022AEE16600A83B79 /* Feedback.swift */, 145 | ); 146 | path = Sources; 147 | sourceTree = ""; 148 | }; 149 | /* End PBXGroup section */ 150 | 151 | /* Begin PBXHeadersBuildPhase section */ 152 | B2C443332338BE05006D7C3B /* Headers */ = { 153 | isa = PBXHeadersBuildPhase; 154 | buildActionMask = 2147483647; 155 | files = ( 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXHeadersBuildPhase section */ 160 | 161 | /* Begin PBXNativeTarget section */ 162 | 65E47D6522ADB1E600A83B79 /* Example */ = { 163 | isa = PBXNativeTarget; 164 | buildConfigurationList = 65E47D7A22ADB1E800A83B79 /* Build configuration list for PBXNativeTarget "Example" */; 165 | buildPhases = ( 166 | 65E47D6222ADB1E600A83B79 /* Sources */, 167 | 65E47D6322ADB1E600A83B79 /* Frameworks */, 168 | 65E47D6422ADB1E600A83B79 /* Resources */, 169 | B2C443442338BE05006D7C3B /* Embed Frameworks */, 170 | ); 171 | buildRules = ( 172 | ); 173 | dependencies = ( 174 | B2C4433E2338BE05006D7C3B /* PBXTargetDependency */, 175 | ); 176 | name = Example; 177 | productName = Cycler; 178 | productReference = 65E47D6622ADB1E600A83B79 /* Example.app */; 179 | productType = "com.apple.product-type.application"; 180 | }; 181 | B2C443372338BE05006D7C3B /* Cycler */ = { 182 | isa = PBXNativeTarget; 183 | buildConfigurationList = B2C443412338BE05006D7C3B /* Build configuration list for PBXNativeTarget "Cycler" */; 184 | buildPhases = ( 185 | B2C443332338BE05006D7C3B /* Headers */, 186 | B2C443342338BE05006D7C3B /* Sources */, 187 | B2C443352338BE05006D7C3B /* Frameworks */, 188 | B2C443362338BE05006D7C3B /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | ); 194 | name = Cycler; 195 | productName = Cycler; 196 | productReference = B2C443382338BE05006D7C3B /* Cycler.framework */; 197 | productType = "com.apple.product-type.framework"; 198 | }; 199 | /* End PBXNativeTarget section */ 200 | 201 | /* Begin PBXProject section */ 202 | 65E47D5E22ADB1E600A83B79 /* Project object */ = { 203 | isa = PBXProject; 204 | attributes = { 205 | LastSwiftUpdateCheck = 1100; 206 | LastUpgradeCheck = 1100; 207 | ORGANIZATIONNAME = "Anders Ha"; 208 | TargetAttributes = { 209 | 65E47D6522ADB1E600A83B79 = { 210 | CreatedOnToolsVersion = 11.0; 211 | }; 212 | B2C443372338BE05006D7C3B = { 213 | CreatedOnToolsVersion = 11.0; 214 | }; 215 | }; 216 | }; 217 | buildConfigurationList = 65E47D6122ADB1E600A83B79 /* Build configuration list for PBXProject "Cycler" */; 218 | compatibilityVersion = "Xcode 9.3"; 219 | developmentRegion = en; 220 | hasScannedForEncodings = 0; 221 | knownRegions = ( 222 | en, 223 | Base, 224 | ); 225 | mainGroup = 65E47D5D22ADB1E600A83B79; 226 | productRefGroup = 65E47D6722ADB1E600A83B79 /* Products */; 227 | projectDirPath = ""; 228 | projectRoot = ""; 229 | targets = ( 230 | 65E47D6522ADB1E600A83B79 /* Example */, 231 | B2C443372338BE05006D7C3B /* Cycler */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | 65E47D6422ADB1E600A83B79 /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | 65E47D7622ADB1E800A83B79 /* LaunchScreen.storyboard in Resources */, 242 | 65E47D7322ADB1E800A83B79 /* Preview Assets.xcassets in Resources */, 243 | 65E47D7022ADB1E800A83B79 /* Assets.xcassets in Resources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | B2C443362338BE05006D7C3B /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXResourcesBuildPhase section */ 255 | 256 | /* Begin PBXSourcesBuildPhase section */ 257 | 65E47D6222ADB1E600A83B79 /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 65E47D6A22ADB1E600A83B79 /* AppDelegate.swift in Sources */, 262 | 65E47D8222ADBD4E00A83B79 /* CounterViewModel.swift in Sources */, 263 | 65E47D6C22ADB1E600A83B79 /* SceneDelegate.swift in Sources */, 264 | 65E47D6E22ADB1E600A83B79 /* CounterView.swift in Sources */, 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | }; 268 | B2C443342338BE05006D7C3B /* Sources */ = { 269 | isa = PBXSourcesBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | B2C443472338BF32006D7C3B /* ViewModel.swift in Sources */, 273 | B2C443482338BF32006D7C3B /* FeedbackLoop.swift in Sources */, 274 | B2C443492338BF32006D7C3B /* Feedback.swift in Sources */, 275 | B2C443462338BF32006D7C3B /* BoundView.swift in Sources */, 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | /* End PBXSourcesBuildPhase section */ 280 | 281 | /* Begin PBXTargetDependency section */ 282 | B2C4433E2338BE05006D7C3B /* PBXTargetDependency */ = { 283 | isa = PBXTargetDependency; 284 | target = B2C443372338BE05006D7C3B /* Cycler */; 285 | targetProxy = B2C4433D2338BE05006D7C3B /* PBXContainerItemProxy */; 286 | }; 287 | /* End PBXTargetDependency section */ 288 | 289 | /* Begin PBXVariantGroup section */ 290 | 65E47D7422ADB1E800A83B79 /* LaunchScreen.storyboard */ = { 291 | isa = PBXVariantGroup; 292 | children = ( 293 | 65E47D7522ADB1E800A83B79 /* Base */, 294 | ); 295 | name = LaunchScreen.storyboard; 296 | sourceTree = ""; 297 | }; 298 | /* End PBXVariantGroup section */ 299 | 300 | /* Begin XCBuildConfiguration section */ 301 | 65E47D7822ADB1E800A83B79 /* Debug */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ALWAYS_SEARCH_USER_PATHS = NO; 305 | CLANG_ANALYZER_NONNULL = YES; 306 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 308 | CLANG_CXX_LIBRARY = "libc++"; 309 | CLANG_ENABLE_MODULES = YES; 310 | CLANG_ENABLE_OBJC_ARC = YES; 311 | CLANG_ENABLE_OBJC_WEAK = YES; 312 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_COMMA = YES; 315 | CLANG_WARN_CONSTANT_CONVERSION = YES; 316 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 317 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 318 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 319 | CLANG_WARN_EMPTY_BODY = YES; 320 | CLANG_WARN_ENUM_CONVERSION = YES; 321 | CLANG_WARN_INFINITE_RECURSION = YES; 322 | CLANG_WARN_INT_CONVERSION = YES; 323 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 324 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 325 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 328 | CLANG_WARN_STRICT_PROTOTYPES = YES; 329 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 330 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 331 | CLANG_WARN_UNREACHABLE_CODE = YES; 332 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 333 | COPY_PHASE_STRIP = NO; 334 | DEBUG_INFORMATION_FORMAT = dwarf; 335 | ENABLE_STRICT_OBJC_MSGSEND = YES; 336 | ENABLE_TESTABILITY = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu11; 338 | GCC_DYNAMIC_NO_PIC = NO; 339 | GCC_NO_COMMON_BLOCKS = YES; 340 | GCC_OPTIMIZATION_LEVEL = 0; 341 | GCC_PREPROCESSOR_DEFINITIONS = ( 342 | "DEBUG=1", 343 | "$(inherited)", 344 | ); 345 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 346 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 347 | GCC_WARN_UNDECLARED_SELECTOR = YES; 348 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 349 | GCC_WARN_UNUSED_FUNCTION = YES; 350 | GCC_WARN_UNUSED_VARIABLE = YES; 351 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 352 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 353 | MTL_FAST_MATH = YES; 354 | ONLY_ACTIVE_ARCH = YES; 355 | SDKROOT = iphoneos; 356 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 357 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 358 | }; 359 | name = Debug; 360 | }; 361 | 65E47D7922ADB1E800A83B79 /* Release */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ALWAYS_SEARCH_USER_PATHS = NO; 365 | CLANG_ANALYZER_NONNULL = YES; 366 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 367 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 368 | CLANG_CXX_LIBRARY = "libc++"; 369 | CLANG_ENABLE_MODULES = YES; 370 | CLANG_ENABLE_OBJC_ARC = YES; 371 | CLANG_ENABLE_OBJC_WEAK = YES; 372 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 373 | CLANG_WARN_BOOL_CONVERSION = YES; 374 | CLANG_WARN_COMMA = YES; 375 | CLANG_WARN_CONSTANT_CONVERSION = YES; 376 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 377 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 378 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 379 | CLANG_WARN_EMPTY_BODY = YES; 380 | CLANG_WARN_ENUM_CONVERSION = YES; 381 | CLANG_WARN_INFINITE_RECURSION = YES; 382 | CLANG_WARN_INT_CONVERSION = YES; 383 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 384 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 385 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 386 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 387 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 388 | CLANG_WARN_STRICT_PROTOTYPES = YES; 389 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 390 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 391 | CLANG_WARN_UNREACHABLE_CODE = YES; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | COPY_PHASE_STRIP = NO; 394 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 395 | ENABLE_NS_ASSERTIONS = NO; 396 | ENABLE_STRICT_OBJC_MSGSEND = YES; 397 | GCC_C_LANGUAGE_STANDARD = gnu11; 398 | GCC_NO_COMMON_BLOCKS = YES; 399 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 400 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 401 | GCC_WARN_UNDECLARED_SELECTOR = YES; 402 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 403 | GCC_WARN_UNUSED_FUNCTION = YES; 404 | GCC_WARN_UNUSED_VARIABLE = YES; 405 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 406 | MTL_ENABLE_DEBUG_INFO = NO; 407 | MTL_FAST_MATH = YES; 408 | SDKROOT = iphoneos; 409 | SWIFT_COMPILATION_MODE = wholemodule; 410 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 411 | VALIDATE_PRODUCT = YES; 412 | }; 413 | name = Release; 414 | }; 415 | 65E47D7B22ADB1E800A83B79 /* Debug */ = { 416 | isa = XCBuildConfiguration; 417 | buildSettings = { 418 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 419 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 420 | CODE_SIGN_STYLE = Automatic; 421 | DEVELOPMENT_ASSET_PATHS = "Example/Preview\\ Content"; 422 | DEVELOPMENT_TEAM = BYSBHXM2D6; 423 | ENABLE_PREVIEWS = YES; 424 | INFOPLIST_FILE = Example/Info.plist; 425 | LD_RUNPATH_SEARCH_PATHS = ( 426 | "$(inherited)", 427 | "@executable_path/Frameworks", 428 | ); 429 | PRODUCT_BUNDLE_IDENTIFIER = com.andersha.Cycle.Cycler; 430 | PRODUCT_NAME = Example; 431 | SWIFT_VERSION = 5.0; 432 | TARGETED_DEVICE_FAMILY = "1,2"; 433 | }; 434 | name = Debug; 435 | }; 436 | 65E47D7C22ADB1E800A83B79 /* Release */ = { 437 | isa = XCBuildConfiguration; 438 | buildSettings = { 439 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 440 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 441 | CODE_SIGN_STYLE = Automatic; 442 | DEVELOPMENT_ASSET_PATHS = "Example/Preview\\ Content"; 443 | DEVELOPMENT_TEAM = BYSBHXM2D6; 444 | ENABLE_PREVIEWS = YES; 445 | INFOPLIST_FILE = Example/Info.plist; 446 | LD_RUNPATH_SEARCH_PATHS = ( 447 | "$(inherited)", 448 | "@executable_path/Frameworks", 449 | ); 450 | PRODUCT_BUNDLE_IDENTIFIER = com.andersha.Cycle.Cycler; 451 | PRODUCT_NAME = Example; 452 | SWIFT_VERSION = 5.0; 453 | TARGETED_DEVICE_FAMILY = "1,2"; 454 | }; 455 | name = Release; 456 | }; 457 | B2C443422338BE05006D7C3B /* Debug */ = { 458 | isa = XCBuildConfiguration; 459 | buildSettings = { 460 | CODE_SIGN_STYLE = Automatic; 461 | CURRENT_PROJECT_VERSION = 1; 462 | DEFINES_MODULE = YES; 463 | DEVELOPMENT_TEAM = BYSBHXM2D6; 464 | DYLIB_COMPATIBILITY_VERSION = 1; 465 | DYLIB_CURRENT_VERSION = 1; 466 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 467 | INFOPLIST_FILE = Cycler/Info.plist; 468 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 469 | LD_RUNPATH_SEARCH_PATHS = ( 470 | "$(inherited)", 471 | "@executable_path/Frameworks", 472 | "@loader_path/Frameworks", 473 | ); 474 | PRODUCT_BUNDLE_IDENTIFIER = com.andersha.Cycle.Cycler.Cycler; 475 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 476 | SKIP_INSTALL = YES; 477 | SWIFT_VERSION = 5.0; 478 | TARGETED_DEVICE_FAMILY = "1,2"; 479 | VERSIONING_SYSTEM = "apple-generic"; 480 | VERSION_INFO_PREFIX = ""; 481 | }; 482 | name = Debug; 483 | }; 484 | B2C443432338BE05006D7C3B /* Release */ = { 485 | isa = XCBuildConfiguration; 486 | buildSettings = { 487 | CODE_SIGN_STYLE = Automatic; 488 | CURRENT_PROJECT_VERSION = 1; 489 | DEFINES_MODULE = YES; 490 | DEVELOPMENT_TEAM = BYSBHXM2D6; 491 | DYLIB_COMPATIBILITY_VERSION = 1; 492 | DYLIB_CURRENT_VERSION = 1; 493 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 494 | INFOPLIST_FILE = Cycler/Info.plist; 495 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 496 | LD_RUNPATH_SEARCH_PATHS = ( 497 | "$(inherited)", 498 | "@executable_path/Frameworks", 499 | "@loader_path/Frameworks", 500 | ); 501 | PRODUCT_BUNDLE_IDENTIFIER = com.andersha.Cycle.Cycler.Cycler; 502 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 503 | SKIP_INSTALL = YES; 504 | SWIFT_VERSION = 5.0; 505 | TARGETED_DEVICE_FAMILY = "1,2"; 506 | VERSIONING_SYSTEM = "apple-generic"; 507 | VERSION_INFO_PREFIX = ""; 508 | }; 509 | name = Release; 510 | }; 511 | /* End XCBuildConfiguration section */ 512 | 513 | /* Begin XCConfigurationList section */ 514 | 65E47D6122ADB1E600A83B79 /* Build configuration list for PBXProject "Cycler" */ = { 515 | isa = XCConfigurationList; 516 | buildConfigurations = ( 517 | 65E47D7822ADB1E800A83B79 /* Debug */, 518 | 65E47D7922ADB1E800A83B79 /* Release */, 519 | ); 520 | defaultConfigurationIsVisible = 0; 521 | defaultConfigurationName = Release; 522 | }; 523 | 65E47D7A22ADB1E800A83B79 /* Build configuration list for PBXNativeTarget "Example" */ = { 524 | isa = XCConfigurationList; 525 | buildConfigurations = ( 526 | 65E47D7B22ADB1E800A83B79 /* Debug */, 527 | 65E47D7C22ADB1E800A83B79 /* Release */, 528 | ); 529 | defaultConfigurationIsVisible = 0; 530 | defaultConfigurationName = Release; 531 | }; 532 | B2C443412338BE05006D7C3B /* Build configuration list for PBXNativeTarget "Cycler" */ = { 533 | isa = XCConfigurationList; 534 | buildConfigurations = ( 535 | B2C443422338BE05006D7C3B /* Debug */, 536 | B2C443432338BE05006D7C3B /* Release */, 537 | ); 538 | defaultConfigurationIsVisible = 0; 539 | defaultConfigurationName = Release; 540 | }; 541 | /* End XCConfigurationList section */ 542 | }; 543 | rootObject = 65E47D5E22ADB1E600A83B79 /* Project object */; 544 | } 545 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/project.xcworkspace/xcuserdata/rui.peres.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andersio/Cycler/235ecdc07eea49d2908413e2cc1210936012406a/Cycler.xcodeproj/project.xcworkspace/xcuserdata/rui.peres.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Cycler.xcodeproj/xcshareddata/xcschemes/Cycler.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/xcuserdata/anders.ha.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 21 | 22 | 23 | 25 | 37 | 38 | 39 | 41 | 53 | 54 | 55 | 57 | 69 | 70 | 71 | 73 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/xcuserdata/anders.ha.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Cycler.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Cycler.xcodeproj/xcuserdata/rui.peres.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Cycler.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 1 11 | 12 | Example.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 65E47D6522ADB1E600A83B79 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Cycler/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 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Cycler/Sources/BoundView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import Combine 3 | 4 | public struct BoundView: View { 5 | public let content: (StateSnapshot) -> Content 6 | @ObservedObject private var viewModel: Entity 7 | 8 | public init( 9 | _ viewModel: Entity, 10 | @ViewBuilder content: @escaping (StateSnapshot) -> Content 11 | ) { 12 | self.viewModel = viewModel 13 | self.content = content 14 | } 15 | 16 | public var body: some View { 17 | return content( 18 | StateSnapshot(state: viewModel.state, entity: viewModel) 19 | ) 20 | } 21 | } 22 | 23 | /// A snapshot of the state of the view model bound with a `BoundView`. 24 | /// 25 | /// You can access any readable property of `state` by using the dot syntax directly on a 26 | /// `StateSnapshot`. To create bindings with writable properties of the state, use `subscript(_:)` or 27 | /// `binding(for:)`. For other kinds of UI callbacks, define them as an action of your view model, and 28 | /// send them through with `perform(_:)`. 29 | /// 30 | /// - important: The state contained in the snapshot **never changes** regardless of the use of bindings 31 | /// or `perform(_:)` with the snapshot. The snapshot funnels actions and mutations back to 32 | /// the view model. 33 | @dynamicMemberLookup 34 | public struct StateSnapshot { 35 | public let state: Entity.S 36 | public weak var entity: Entity? 37 | 38 | public init(state: Entity.S, entity: Entity) { 39 | self.state = state 40 | self.entity = entity 41 | } 42 | 43 | public func perform(_ action: Entity.A) { 44 | entity?.perform(action) 45 | } 46 | 47 | public subscript(dynamicMember keyPath: KeyPath) -> U { 48 | get { return state[keyPath: keyPath] } 49 | } 50 | 51 | public subscript(keyPath: WritableKeyPath) -> Binding { 52 | return binding(for: keyPath) 53 | } 54 | 55 | public func binding(for keyPath: WritableKeyPath) -> Binding { 56 | return Binding( 57 | get: { self.state[keyPath: keyPath] }, 58 | set: { self.entity?.update($0, for: keyPath) } 59 | ) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Cycler/Sources/Feedback.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | 3 | extension FeedbackLoop { 4 | public struct Feedback { 5 | public let effects: (AnyPublisher) -> AnyPublisher 6 | 7 | public init( 8 | effects: @escaping (AnyPublisher) -> AnyPublisher 9 | ) { 10 | self.effects = { effects($0) } 11 | } 12 | 13 | /// Creates a Feedback which re-evaluates the given effect every time the 14 | /// state changes, and the transform consequentially yields a new value 15 | /// distinct from the last yielded value. 16 | /// 17 | /// If the previous effect is still alive when a new one is about to start, 18 | /// the previous one would automatically be cancelled. 19 | /// 20 | /// - parameters: 21 | /// - transform: The transform to apply on the state. 22 | /// - effecs: The side effect accepting transformed values produced by 23 | /// `transform` and yielding events that eventually affect 24 | /// the state. 25 | public static func skippingRepeated( 26 | _ transform: @escaping (Output) -> U?, 27 | effect: @escaping (U) -> Events 28 | ) -> Feedback where Events.Output == E, Events.Failure == Never { 29 | return Feedback { output -> AnyPublisher in 30 | return output 31 | .map(transform) 32 | .removeDuplicates() 33 | .map { $0.map(effect)?.eraseToAnyPublisher() ?? Empty().eraseToAnyPublisher() } 34 | .switchToLatest() 35 | .eraseToAnyPublisher() 36 | } 37 | } 38 | 39 | public static func positiveEdgeTrigger( 40 | _ predicate: @escaping (Output) -> Bool, 41 | effect: @escaping (Output) -> Events 42 | ) -> Feedback where Events.Output == E, Events.Failure == Never { 43 | return Feedback { output -> AnyPublisher in 44 | var last = false 45 | 46 | return output 47 | .compactMap { output -> AnyPublisher? in 48 | let current = predicate(output) 49 | defer { last = current } 50 | 51 | switch (last, current) { 52 | case (false, true): 53 | return effect(output).eraseToAnyPublisher() 54 | case (true, false): 55 | return Empty().eraseToAnyPublisher() 56 | case (false, false), (true, true): 57 | return nil 58 | } 59 | } 60 | .switchToLatest() 61 | .eraseToAnyPublisher() 62 | } 63 | } 64 | 65 | public static func systemBootstrapped( 66 | effect: @escaping () -> Events 67 | ) -> Feedback where Events.Output == E, Events.Failure == Never { 68 | return Feedback { output -> AnyPublisher in 69 | return output 70 | .filter { $0.input == nil } 71 | .first() 72 | .flatMap { _ in effect() } 73 | .eraseToAnyPublisher() 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Cycler/Sources/FeedbackLoop.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import Dispatch 3 | import Foundation 4 | 5 | open class FeedbackLoop: ViewModel { 6 | public enum Input { 7 | /// A feedback has emitted an event. 8 | case event(E) 9 | 10 | /// An API consumer has triggered an action. 11 | case action(A) 12 | 13 | /// A publicly writable property of the state has been updated by a value 14 | /// supplied by an API consumer. 15 | case updated(PartialKeyPath) 16 | } 17 | 18 | public struct Output { 19 | /// The last processed input. `nil` means the system has just been spun up. 20 | public let input: Input? 21 | 22 | /// The state after having processed `input`. 23 | public let state: S 24 | 25 | public init(state: S, input: Input?) { 26 | self.input = input 27 | self.state = state 28 | } 29 | } 30 | 31 | @StatePublished public var state: S 32 | 33 | public let objectWillChange: PassthroughSubject 34 | 35 | private let outputSubject: CurrentValueSubject 36 | private let reduce: (inout S, Input) -> Void 37 | 38 | // NOTE: Beyond initialization, all inputs must be processed on `queue`. 39 | private let queue: DispatchQueue 40 | private let specificKey = DispatchSpecificKey() 41 | private var disposables = Set() 42 | 43 | public init( 44 | initial: S, 45 | reduce: @escaping (inout S, Input) -> Void, 46 | feedbacks: [Feedback] = [], 47 | usesMainQueue: Bool = true, 48 | qos: DispatchQoS = .default 49 | ) { 50 | self.reduce = reduce 51 | self.objectWillChange = PassthroughSubject() 52 | self.outputSubject = CurrentValueSubject(Output(state: initial, input: nil)) 53 | self._state = .init(subject: outputSubject) 54 | 55 | self.queue = usesMainQueue 56 | ? .main 57 | : DispatchQueue( 58 | label: "FeedbackLoop", 59 | qos: qos, 60 | attributes: [], 61 | autoreleaseFrequency: .inherit, 62 | target: nil 63 | ) 64 | 65 | queue.setSpecific(key: specificKey, value: ()) 66 | 67 | Publishers.MergeMany( 68 | feedbacks.map { $0.effects(AnyPublisher(outputSubject)) } 69 | ) 70 | .sink { [weak self] event in 71 | guard let self = self else { return } 72 | self.process(.event(event)) { _ in } 73 | } 74 | .store(in: &disposables) 75 | } 76 | 77 | deinit { 78 | outputSubject.send(completion: .finished) 79 | objectWillChange.send(completion: .finished) 80 | queue.setSpecific(key: specificKey, value: nil) 81 | } 82 | 83 | public func perform(_ action: A) { 84 | process(.action(action)) { _ in } 85 | } 86 | 87 | public func update(_ value: U, for keyPath: WritableKeyPath) { 88 | process(.updated(keyPath)) { 89 | $0[keyPath: keyPath] = value 90 | } 91 | } 92 | 93 | private func process(_ input: Input, willReduce: @escaping (inout S) -> Void) { 94 | func execute() { 95 | var state = outputSubject.value.state 96 | willReduce(&state) 97 | reduce(&state, input) 98 | outputSubject.value = Output(state: state, input: input) 99 | objectWillChange.send() 100 | } 101 | 102 | if DispatchQueue.getSpecific(key: specificKey) != nil { 103 | execute() 104 | } else { 105 | queue.async(execute: execute) 106 | } 107 | } 108 | 109 | @propertyWrapper 110 | public struct StatePublished { 111 | public var wrappedValue: S { 112 | _read { yield subject.value.state } 113 | } 114 | 115 | public var publisher: AnyPublisher { 116 | return subject.map { $0.state }.eraseToAnyPublisher() 117 | } 118 | 119 | private let subject: CurrentValueSubject 120 | 121 | fileprivate init(subject: CurrentValueSubject) { 122 | self.subject = subject 123 | } 124 | } 125 | } 126 | 127 | private func mainThreadAssertion() { 128 | dispatchPrecondition(condition: .onQueue(.main)) 129 | } 130 | -------------------------------------------------------------------------------- /Cycler/Sources/ViewModel.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public protocol ViewModel: ObservableObject { 4 | associatedtype S 5 | associatedtype A 6 | 7 | var state: S { get } 8 | 9 | func perform(_ action: A) 10 | func update(_ value: U, for keyPath: WritableKeyPath) 11 | } 12 | -------------------------------------------------------------------------------- /Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Cycler 4 | // 5 | // Created by Anders Ha on 09/06/2019. 6 | // Copyright © 2019 Anders Ha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | // Override point for customization after application launch. 16 | return true 17 | } 18 | 19 | func applicationWillTerminate(_ application: UIApplication) { 20 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 21 | } 22 | 23 | // MARK: UISceneSession Lifecycle 24 | 25 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 26 | // Called when a new scene session is being created. 27 | // Use this method to select a configuration to create the new scene with. 28 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 29 | } 30 | 31 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 32 | // Called when the user discards a scene session. 33 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 34 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Example/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 | } -------------------------------------------------------------------------------- /Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/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 | -------------------------------------------------------------------------------- /Example/CounterView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import Combine 3 | import Cycler 4 | 5 | protocol CounterViewModelProtocol: ViewModel 6 | where S == CounterViewModel.State, 7 | A == CounterViewModel.Action {} 8 | 9 | enum ViewLibrary { 10 | static func counter(_ vm: ViewModel) -> some View { 11 | return BoundView(vm) { (state: StateSnapshot) in 12 | VStack { 13 | VStack { 14 | Text(state.displayText) 15 | .font(.largeTitle) 16 | .padding() 17 | HStack { 18 | Spacer() 19 | Button( 20 | action: { state.perform(.minus) }, 21 | label: { Image(systemName: "minus.circle") } 22 | ) 23 | Spacer() 24 | Button( 25 | action: { state.perform(.plus) }, 26 | label: { Image(systemName: "plus.circle") } 27 | ) 28 | Spacer() 29 | }.padding() 30 | } 31 | 32 | List { 33 | Section(header: Text("Settings")) { 34 | Stepper( 35 | value: state.binding(for: \.increment), 36 | in: 1 ... 10, 37 | label: { 38 | Text("Increment: \(state.increment)") 39 | } 40 | ) 41 | HStack { 42 | Text("Format") 43 | TextField( 44 | "%d", 45 | text: state.binding(for: \.format), 46 | onEditingChanged: { _ in }, 47 | onCommit: {} 48 | ) 49 | .multilineTextAlignment(.trailing) 50 | } 51 | 52 | HStack { 53 | Text("Last loaded") 54 | Spacer() 55 | Text((state.lastLoaded.map { "\($0)" } ?? "Never") as String) 56 | .multilineTextAlignment(.trailing) 57 | } 58 | 59 | Button( 60 | action: { state.perform(.pressedStart) }, 61 | label: { Text("Refresh") } 62 | ) 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | #if DEBUG 71 | struct ContentView_Previews : PreviewProvider { 72 | static var previews: some View { 73 | ViewLibrary.counter(MockCounterCycle( 74 | CounterViewModel.State(currentCount: 10, increment: 1) 75 | )) 76 | } 77 | } 78 | 79 | final class MockCounterCycle: CounterViewModelProtocol { 80 | var state: CounterViewModel.State 81 | let didChange: PassthroughSubject 82 | 83 | init(_ value: CounterViewModel.State) { 84 | state = value 85 | didChange = PassthroughSubject() 86 | } 87 | 88 | func perform(_ action: CounterViewModel.Action) {} 89 | func update(_ value: U, for keyPath: WritableKeyPath) {} 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /Example/CounterViewModel.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import Foundation 3 | import Cycler 4 | 5 | final class CounterViewModel: FeedbackLoop, CounterViewModelProtocol { 6 | init() { 7 | super.init( 8 | initial: State(currentCount: 10, increment: 1), 9 | reduce: { state, input in 10 | switch input { 11 | case let .event(.restoreCount(count)): 12 | state.currentCount = count 13 | case .event(.loaded): 14 | state.lastLoaded = Date() 15 | state.isLoading = false 16 | case .updated: 17 | break 18 | case .action(.pressedStart): 19 | state.isLoading = true 20 | case .action(.plus): 21 | state.currentCount += state.increment 22 | case .action(.minus): 23 | state.currentCount -= state.increment 24 | } 25 | }, 26 | feedbacks: [ 27 | .systemBootstrapped { Just(.restoreCount(100)) }, 28 | .positiveEdgeTrigger({ $0.state.isLoading }) { _ in 29 | return Just(.loaded) 30 | } 31 | ] 32 | ) 33 | } 34 | 35 | enum Event { 36 | case restoreCount(Int) 37 | case loaded 38 | } 39 | 40 | enum Action { 41 | case plus 42 | case minus 43 | case pressedStart 44 | } 45 | 46 | struct State { 47 | fileprivate(set) var currentCount: Int 48 | var increment: Int = 1 49 | var format: String = "%d" 50 | 51 | var lastLoaded: Date? 52 | var isLoading: Bool = false 53 | 54 | var displayText: String { 55 | return String(format: format, currentCount) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Example/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 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegate 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Cycler 4 | // 5 | // Created by Anders Ha on 09/06/2019. 6 | // Copyright © 2019 Anders Ha. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | 19 | // Use a UIHostingController as window root view controller. 20 | if let windowScene = scene as? UIWindowScene { 21 | let window = UIWindow(windowScene: windowScene) 22 | window.rootViewController = UIHostingController(rootView: ViewLibrary.counter(CounterViewModel())) 23 | self.window = window 24 | window.makeKeyAndVisible() 25 | } 26 | } 27 | 28 | func sceneDidDisconnect(_ scene: UIScene) { 29 | // Called as the scene is being released by the system. 30 | // This occurs shortly after the scene enters the background, or when its session is discarded. 31 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 32 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 33 | } 34 | 35 | func sceneDidBecomeActive(_ scene: UIScene) { 36 | // Called when the scene has moved from an inactive state to an active state. 37 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 38 | } 39 | 40 | func sceneWillResignActive(_ scene: UIScene) { 41 | // Called when the scene will move from an active state to an inactive state. 42 | // This may occur due to temporary interruptions (ex. an incoming phone call). 43 | } 44 | 45 | func sceneWillEnterForeground(_ scene: UIScene) { 46 | // Called as the scene transitions from the background to the foreground. 47 | // Use this method to undo the changes made on entering the background. 48 | } 49 | 50 | func sceneDidEnterBackground(_ scene: UIScene) { 51 | // Called as the scene transitions from the foreground to the background. 52 | // Use this method to save data, release shared resources, and store enough scene-specific state information 53 | // to restore the scene back to its current state. 54 | } 55 | 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "Cycler", 6 | platforms: [ 7 | .iOS(.v13) 8 | ], 9 | products: [ 10 | .library( 11 | name: "Cycler", 12 | targets: ["Cycler"]), 13 | ], 14 | targets: [ 15 | .target( 16 | name: "Cycler", 17 | dependencies: [], 18 | path: "Sources"), 19 | ], 20 | swiftLanguageVersions: [ 21 | .version("5.1") 22 | ] 23 | ) 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Notice of archival 2 | Check out [ReactiveCocoa/Loop](https://github.com/ReactiveCocoa/Loop) for a [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift)-based unidirectional data flow architecture that can integrate with SwiftUI. If you aren't adopting SwiftUI just yet, it can be used in conjunction with declarative UI frameworks like [Bento](https://github.com/babylonpartners/Bento) or [Carbon](https://github.com/ra1028/Carbon) to provide you a SwiftUI-like developer experience. 3 | 4 | Check out [Pointfree's Compositional Architecture](https://github.com/pointfreeco/swift-composable-architecture) if you are building a SwiftUI + Combine application from scratch, and you aren't already familiar with the unidirectional data flow pattern. 5 | 6 | 7 | ### Data flow 8 | ![](dataflow.png) 9 | -------------------------------------------------------------------------------- /dataflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andersio/Cycler/235ecdc07eea49d2908413e2cc1210936012406a/dataflow.png --------------------------------------------------------------------------------