├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .swiftpm └── xcode │ ├── package.xcworkspace │ └── contents.xcworkspacedata │ └── xcshareddata │ └── xcschemes │ └── ComposableOpenURL.xcscheme ├── ComposableOpenURL.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── swiftpm │ └── Package.resolved ├── Demo Project ├── ComposableOpenURLDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── ComposableOpenURLDemo │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── ComposableOpenURLDemoApp.swift │ ├── Info.plist │ ├── OpeningURLView.swift │ └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json ├── LICENSE ├── Package.resolved ├── Package.swift ├── README.md ├── Sources └── ComposableOpenURL │ └── OpenURL.swift └── Tests └── ComposableOpenURLTests └── ComposableOpenURLTests.swift /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build-and-test: 11 | runs-on: macos-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Build and Run Tests 16 | uses: sersoft-gmbh/xcodebuild-action@v1.3 17 | with: 18 | workspace: ComposableOpenURL.xcworkspace 19 | scheme: ComposableOpenURL 20 | destination: "platform=iOS Simulator,OS=15.2,name=iPhone 12" 21 | action: test 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.dia 28 | 29 | ## App packaging 30 | *.ipa 31 | *.dSYM.zip 32 | *.dSYM 33 | 34 | ## Playgrounds 35 | timeline.xctimeline 36 | playground.xcworkspace 37 | 38 | # Swift Package Manager 39 | # 40 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 41 | # Packages/ 42 | # Package.pins 43 | # Package.resolved 44 | # *.xcodeproj 45 | # 46 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 47 | # hence it is not needed unless you have added a package configuration file to your project 48 | # .swiftpm 49 | 50 | .build/ 51 | 52 | # CocoaPods 53 | # 54 | # We recommend against adding the Pods directory to your .gitignore. However 55 | # you should judge for yourself, the pros and cons are mentioned at: 56 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 57 | # 58 | # Pods/ 59 | # 60 | # Add this line if you want to avoid checking in source code from the Xcode workspace 61 | # *.xcworkspace 62 | 63 | # Carthage 64 | # 65 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 66 | # Carthage/Checkouts 67 | 68 | Carthage/Build/ 69 | 70 | # Accio dependency management 71 | Dependencies/ 72 | .accio/ 73 | 74 | # fastlane 75 | # 76 | # It is recommended to not store the screenshots in the git repo. 77 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 78 | # For more information about the recommended setup visit: 79 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 80 | 81 | fastlane/report.xml 82 | fastlane/Preview.html 83 | fastlane/screenshots/**/*.png 84 | fastlane/test_output 85 | 86 | # Code Injection 87 | # 88 | # After new code Injection tools there's a generated folder /iOSInjectionProject 89 | # https://github.com/johnno1962/injectionforxcode 90 | 91 | iOSInjectionProject/ 92 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.swiftpm/xcode/xcshareddata/xcschemes/ComposableOpenURL.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /ComposableOpenURL.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ComposableOpenURL.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ComposableOpenURL.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "combine-schedulers", 6 | "repositoryURL": "https://github.com/pointfreeco/combine-schedulers", 7 | "state": { 8 | "branch": null, 9 | "revision": "ae2f434e81017bb7de02c168fb0bde83cd8370c1", 10 | "version": "0.3.1" 11 | } 12 | }, 13 | { 14 | "package": "swift-case-paths", 15 | "repositoryURL": "https://github.com/pointfreeco/swift-case-paths", 16 | "state": { 17 | "branch": null, 18 | "revision": "1aa1bf7c4069d9ba2f7edd36dbfc96ff1c58cbff", 19 | "version": "0.1.3" 20 | } 21 | }, 22 | { 23 | "package": "swift-composable-architecture", 24 | "repositoryURL": "https://github.com/pointfreeco/swift-composable-architecture", 25 | "state": { 26 | "branch": null, 27 | "revision": "a116fff6d4dbbad7c17308edf04e40a50b74e088", 28 | "version": "0.16.0" 29 | } 30 | } 31 | ] 32 | }, 33 | "version": 1 34 | } 35 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A3AAED162603FEDF00314F56 /* ComposableOpenURLDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3AAED152603FEDF00314F56 /* ComposableOpenURLDemoApp.swift */; }; 11 | A3AAED182603FEDF00314F56 /* OpeningURLView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3AAED172603FEDF00314F56 /* OpeningURLView.swift */; }; 12 | A3AAED1A2603FEE000314F56 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A3AAED192603FEE000314F56 /* Assets.xcassets */; }; 13 | A3AAED1D2603FEE000314F56 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A3AAED1C2603FEE000314F56 /* Preview Assets.xcassets */; }; 14 | A3AAED282604008800314F56 /* ComposableOpenURL in Frameworks */ = {isa = PBXBuildFile; productRef = A3AAED272604008800314F56 /* ComposableOpenURL */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | A3AAED122603FEDF00314F56 /* ComposableOpenURLDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ComposableOpenURLDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | A3AAED152603FEDF00314F56 /* ComposableOpenURLDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposableOpenURLDemoApp.swift; sourceTree = ""; }; 20 | A3AAED172603FEDF00314F56 /* OpeningURLView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpeningURLView.swift; sourceTree = ""; }; 21 | A3AAED192603FEE000314F56 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | A3AAED1C2603FEE000314F56 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | A3AAED1E2603FEE000314F56 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24 | /* End PBXFileReference section */ 25 | 26 | /* Begin PBXFrameworksBuildPhase section */ 27 | A3AAED0F2603FEDF00314F56 /* Frameworks */ = { 28 | isa = PBXFrameworksBuildPhase; 29 | buildActionMask = 2147483647; 30 | files = ( 31 | A3AAED282604008800314F56 /* ComposableOpenURL in Frameworks */, 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | A3AAED092603FEDF00314F56 = { 39 | isa = PBXGroup; 40 | children = ( 41 | A3AAED142603FEDF00314F56 /* ComposableOpenURLDemo */, 42 | A3AAED132603FEDF00314F56 /* Products */, 43 | A3AAED262604008800314F56 /* Frameworks */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | A3AAED132603FEDF00314F56 /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | A3AAED122603FEDF00314F56 /* ComposableOpenURLDemo.app */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | A3AAED142603FEDF00314F56 /* ComposableOpenURLDemo */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | A3AAED152603FEDF00314F56 /* ComposableOpenURLDemoApp.swift */, 59 | A3AAED172603FEDF00314F56 /* OpeningURLView.swift */, 60 | A3AAED192603FEE000314F56 /* Assets.xcassets */, 61 | A3AAED1E2603FEE000314F56 /* Info.plist */, 62 | A3AAED1B2603FEE000314F56 /* Preview Content */, 63 | ); 64 | path = ComposableOpenURLDemo; 65 | sourceTree = ""; 66 | }; 67 | A3AAED1B2603FEE000314F56 /* Preview Content */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | A3AAED1C2603FEE000314F56 /* Preview Assets.xcassets */, 71 | ); 72 | path = "Preview Content"; 73 | sourceTree = ""; 74 | }; 75 | A3AAED262604008800314F56 /* Frameworks */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | ); 79 | name = Frameworks; 80 | sourceTree = ""; 81 | }; 82 | /* End PBXGroup section */ 83 | 84 | /* Begin PBXNativeTarget section */ 85 | A3AAED112603FEDF00314F56 /* ComposableOpenURLDemo */ = { 86 | isa = PBXNativeTarget; 87 | buildConfigurationList = A3AAED212603FEE000314F56 /* Build configuration list for PBXNativeTarget "ComposableOpenURLDemo" */; 88 | buildPhases = ( 89 | A3AAED0E2603FEDF00314F56 /* Sources */, 90 | A3AAED0F2603FEDF00314F56 /* Frameworks */, 91 | A3AAED102603FEDF00314F56 /* Resources */, 92 | ); 93 | buildRules = ( 94 | ); 95 | dependencies = ( 96 | ); 97 | name = ComposableOpenURLDemo; 98 | packageProductDependencies = ( 99 | A3AAED272604008800314F56 /* ComposableOpenURL */, 100 | ); 101 | productName = ComposableOpenURLDemo; 102 | productReference = A3AAED122603FEDF00314F56 /* ComposableOpenURLDemo.app */; 103 | productType = "com.apple.product-type.application"; 104 | }; 105 | /* End PBXNativeTarget section */ 106 | 107 | /* Begin PBXProject section */ 108 | A3AAED0A2603FEDF00314F56 /* Project object */ = { 109 | isa = PBXProject; 110 | attributes = { 111 | LastSwiftUpdateCheck = 1240; 112 | LastUpgradeCheck = 1240; 113 | TargetAttributes = { 114 | A3AAED112603FEDF00314F56 = { 115 | CreatedOnToolsVersion = 12.4; 116 | }; 117 | }; 118 | }; 119 | buildConfigurationList = A3AAED0D2603FEDF00314F56 /* Build configuration list for PBXProject "ComposableOpenURLDemo" */; 120 | compatibilityVersion = "Xcode 9.3"; 121 | developmentRegion = en; 122 | hasScannedForEncodings = 0; 123 | knownRegions = ( 124 | en, 125 | Base, 126 | ); 127 | mainGroup = A3AAED092603FEDF00314F56; 128 | productRefGroup = A3AAED132603FEDF00314F56 /* Products */; 129 | projectDirPath = ""; 130 | projectRoot = ""; 131 | targets = ( 132 | A3AAED112603FEDF00314F56 /* ComposableOpenURLDemo */, 133 | ); 134 | }; 135 | /* End PBXProject section */ 136 | 137 | /* Begin PBXResourcesBuildPhase section */ 138 | A3AAED102603FEDF00314F56 /* Resources */ = { 139 | isa = PBXResourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | A3AAED1D2603FEE000314F56 /* Preview Assets.xcassets in Resources */, 143 | A3AAED1A2603FEE000314F56 /* Assets.xcassets in Resources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | A3AAED0E2603FEDF00314F56 /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | A3AAED182603FEDF00314F56 /* OpeningURLView.swift in Sources */, 155 | A3AAED162603FEDF00314F56 /* ComposableOpenURLDemoApp.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin XCBuildConfiguration section */ 162 | A3AAED1F2603FEE000314F56 /* Debug */ = { 163 | isa = XCBuildConfiguration; 164 | buildSettings = { 165 | ALWAYS_SEARCH_USER_PATHS = NO; 166 | CLANG_ANALYZER_NONNULL = YES; 167 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 168 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 169 | CLANG_CXX_LIBRARY = "libc++"; 170 | CLANG_ENABLE_MODULES = YES; 171 | CLANG_ENABLE_OBJC_ARC = YES; 172 | CLANG_ENABLE_OBJC_WEAK = YES; 173 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 174 | CLANG_WARN_BOOL_CONVERSION = YES; 175 | CLANG_WARN_COMMA = YES; 176 | CLANG_WARN_CONSTANT_CONVERSION = YES; 177 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 180 | CLANG_WARN_EMPTY_BODY = YES; 181 | CLANG_WARN_ENUM_CONVERSION = YES; 182 | CLANG_WARN_INFINITE_RECURSION = YES; 183 | CLANG_WARN_INT_CONVERSION = YES; 184 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 185 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 186 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 187 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 188 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 189 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 190 | CLANG_WARN_STRICT_PROTOTYPES = YES; 191 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 192 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 193 | CLANG_WARN_UNREACHABLE_CODE = YES; 194 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 195 | COPY_PHASE_STRIP = NO; 196 | DEBUG_INFORMATION_FORMAT = dwarf; 197 | ENABLE_STRICT_OBJC_MSGSEND = YES; 198 | ENABLE_TESTABILITY = YES; 199 | GCC_C_LANGUAGE_STANDARD = gnu11; 200 | GCC_DYNAMIC_NO_PIC = NO; 201 | GCC_NO_COMMON_BLOCKS = YES; 202 | GCC_OPTIMIZATION_LEVEL = 0; 203 | GCC_PREPROCESSOR_DEFINITIONS = ( 204 | "DEBUG=1", 205 | "$(inherited)", 206 | ); 207 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 208 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 209 | GCC_WARN_UNDECLARED_SELECTOR = YES; 210 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 211 | GCC_WARN_UNUSED_FUNCTION = YES; 212 | GCC_WARN_UNUSED_VARIABLE = YES; 213 | IPHONEOS_DEPLOYMENT_TARGET = 14.4; 214 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 215 | MTL_FAST_MATH = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 219 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 220 | }; 221 | name = Debug; 222 | }; 223 | A3AAED202603FEE000314F56 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_ANALYZER_NONNULL = YES; 228 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_ENABLE_OBJC_WEAK = YES; 234 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_COMMA = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 239 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 240 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 241 | CLANG_WARN_EMPTY_BODY = YES; 242 | CLANG_WARN_ENUM_CONVERSION = YES; 243 | CLANG_WARN_INFINITE_RECURSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 246 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 247 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 249 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 250 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 251 | CLANG_WARN_STRICT_PROTOTYPES = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu11; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 14.4; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | MTL_FAST_MATH = YES; 271 | SDKROOT = iphoneos; 272 | SWIFT_COMPILATION_MODE = wholemodule; 273 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 274 | VALIDATE_PRODUCT = YES; 275 | }; 276 | name = Release; 277 | }; 278 | A3AAED222603FEE000314F56 /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 282 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 283 | CODE_SIGN_STYLE = Automatic; 284 | DEVELOPMENT_ASSET_PATHS = "\"ComposableOpenURLDemo/Preview Content\""; 285 | DEVELOPMENT_TEAM = ZZVQ8B5T69; 286 | ENABLE_PREVIEWS = YES; 287 | INFOPLIST_FILE = ComposableOpenURLDemo/Info.plist; 288 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 289 | LD_RUNPATH_SEARCH_PATHS = ( 290 | "$(inherited)", 291 | "@executable_path/Frameworks", 292 | ); 293 | PRODUCT_BUNDLE_IDENTIFIER = co.uk.lukeredpath.ComposableOpenURLDemo; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | SWIFT_VERSION = 5.0; 296 | TARGETED_DEVICE_FAMILY = "1,2"; 297 | }; 298 | name = Debug; 299 | }; 300 | A3AAED232603FEE000314F56 /* Release */ = { 301 | isa = XCBuildConfiguration; 302 | buildSettings = { 303 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 304 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 305 | CODE_SIGN_STYLE = Automatic; 306 | DEVELOPMENT_ASSET_PATHS = "\"ComposableOpenURLDemo/Preview Content\""; 307 | DEVELOPMENT_TEAM = ZZVQ8B5T69; 308 | ENABLE_PREVIEWS = YES; 309 | INFOPLIST_FILE = ComposableOpenURLDemo/Info.plist; 310 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 311 | LD_RUNPATH_SEARCH_PATHS = ( 312 | "$(inherited)", 313 | "@executable_path/Frameworks", 314 | ); 315 | PRODUCT_BUNDLE_IDENTIFIER = co.uk.lukeredpath.ComposableOpenURLDemo; 316 | PRODUCT_NAME = "$(TARGET_NAME)"; 317 | SWIFT_VERSION = 5.0; 318 | TARGETED_DEVICE_FAMILY = "1,2"; 319 | }; 320 | name = Release; 321 | }; 322 | /* End XCBuildConfiguration section */ 323 | 324 | /* Begin XCConfigurationList section */ 325 | A3AAED0D2603FEDF00314F56 /* Build configuration list for PBXProject "ComposableOpenURLDemo" */ = { 326 | isa = XCConfigurationList; 327 | buildConfigurations = ( 328 | A3AAED1F2603FEE000314F56 /* Debug */, 329 | A3AAED202603FEE000314F56 /* Release */, 330 | ); 331 | defaultConfigurationIsVisible = 0; 332 | defaultConfigurationName = Release; 333 | }; 334 | A3AAED212603FEE000314F56 /* Build configuration list for PBXNativeTarget "ComposableOpenURLDemo" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | A3AAED222603FEE000314F56 /* Debug */, 338 | A3AAED232603FEE000314F56 /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | /* End XCConfigurationList section */ 344 | 345 | /* Begin XCSwiftPackageProductDependency section */ 346 | A3AAED272604008800314F56 /* ComposableOpenURL */ = { 347 | isa = XCSwiftPackageProductDependency; 348 | productName = ComposableOpenURL; 349 | }; 350 | /* End XCSwiftPackageProductDependency section */ 351 | }; 352 | rootObject = A3AAED0A2603FEDF00314F56 /* Project object */; 353 | } 354 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/ComposableOpenURLDemoApp.swift: -------------------------------------------------------------------------------- 1 | import ComposableArchitecture 2 | import SwiftUI 3 | 4 | @main 5 | struct ComposableOpenURLDemoApp: App { 6 | var body: some Scene { 7 | WindowGroup { 8 | OpeningURLView( 9 | store: Store( 10 | initialState: OpeningURLState(), 11 | reducer: openingURLReducer, 12 | environment: OpeningURLEnvironment( 13 | mainQueue: DispatchQueue.main.eraseToAnyScheduler() 14 | ) 15 | ) 16 | ) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/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 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/OpeningURLView.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Community.com, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | import ComposableArchitecture 16 | import ComposableOpenURL 17 | import SwiftUI 18 | 19 | private let readMe = """ 20 | This file demonstrates how to open external URLs using state and a SwiftUI view modifier. 21 | 22 | SwiftUI and UIKit provide some simple tools for opening external URLs, such as the `Link` 23 | view and `UIApplication.shared.OpeningURL` and sometimes that is all you need for simple static 24 | links within your app. 25 | 26 | Sometimes however, you might need to trigger the opening of a URL as the result of some 27 | explicit action sent to the store, such as an action on an `AlertState` button or received 28 | from some `Effect`. 29 | 30 | The library comes with a utility to embed the functionality of opening URLs directly within 31 | your feature domain with minimal setup and allows you to trigger the opening of a URL with 32 | a simple state mutation, which also makes it really easy to test. 33 | """ 34 | 35 | // The state for this screen holds a bunch of values that will drive 36 | struct OpeningURLState: Equatable { 37 | var urlToOpen: URL? 38 | var errorAlert: AlertState? 39 | } 40 | 41 | enum OpeningURLAction: Equatable { 42 | case tappedToOpen(URL?) 43 | case openAfterDelay(URL?, TimeInterval) 44 | case dismissErrorAlert 45 | case openURL(OpenURLViewAction) 46 | } 47 | 48 | struct OpeningURLEnvironment { 49 | let mainQueue: AnySchedulerOf 50 | } 51 | 52 | let openingURLReducer = Reducer< 53 | OpeningURLState, OpeningURLAction, OpeningURLEnvironment 54 | > { 55 | state, action, environment in 56 | switch action { 57 | case let .tappedToOpen(url): 58 | state.urlToOpen = url 59 | return .none 60 | case let .openAfterDelay(url, delay): 61 | return Effect(value: url) 62 | .delay(for: .seconds(delay), scheduler: environment.mainQueue) 63 | .eraseToEffect() 64 | .map(OpeningURLAction.tappedToOpen) 65 | case .openURL(.openedURL(false)): 66 | state.errorAlert = .init( 67 | title: .init("URL Error"), 68 | message: .init("The URL failed to open."), 69 | dismissButton: .cancel() 70 | ) 71 | return .none 72 | case .openURL(.urlNotSupported): 73 | state.errorAlert = .init( 74 | title: .init("URL Error"), 75 | message: .init("The URL is not supported and cannot be opened."), 76 | dismissButton: .cancel() 77 | ) 78 | return .none 79 | case .dismissErrorAlert: 80 | state.errorAlert = nil 81 | return .none 82 | case .openURL: 83 | return .none 84 | } 85 | } 86 | .opensURL( 87 | state: \.urlToOpen, 88 | action: /OpeningURLAction.openURL 89 | ) 90 | 91 | struct OpeningURLView: View { 92 | let store: Store 93 | 94 | var body: some View { 95 | WithViewStore(self.store) { viewStore in 96 | VStack(spacing: 20) { 97 | Button("Open Pointfree.co") { 98 | viewStore.send(.tappedToOpen(URL(string: "https://pointfree.co"))) 99 | } 100 | Button("Open TCA Github Repo") { 101 | viewStore.send(.tappedToOpen(URL(string: "https://github.com/pointfreeco/swift-composable-architecture"))) 102 | } 103 | Button("Open URL with delayed effect") { 104 | viewStore.send(.openAfterDelay(URL(string: "http://example.com"), 2)) 105 | } 106 | Button("Open unsupported URL") { 107 | viewStore.send(.tappedToOpen(URL(string: "gopher://localhost:10000"))) 108 | } 109 | } 110 | } 111 | .navigationBarTitle("Opening URLs") 112 | .alert( 113 | store.scope(state: \.errorAlert), 114 | dismiss: .dismissErrorAlert 115 | ) 116 | .opensURL( 117 | store.scope( 118 | state: \.urlToOpen, 119 | action: OpeningURLAction.openURL 120 | ) 121 | ) 122 | } 123 | } 124 | 125 | struct OpeningURLView_Previews: PreviewProvider { 126 | static var previews: some View { 127 | NavigationView { 128 | OpeningURLView( 129 | store: Store( 130 | initialState: OpeningURLState(), 131 | reducer: openingURLReducer, 132 | environment: OpeningURLEnvironment( 133 | mainQueue: DispatchQueue.main.eraseToAnyScheduler() 134 | ) 135 | ) 136 | ) 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Demo Project/ComposableOpenURLDemo/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2021 Community.com, Inc. 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "combine-schedulers", 6 | "repositoryURL": "https://github.com/pointfreeco/combine-schedulers", 7 | "state": { 8 | "branch": null, 9 | "revision": "4cf088c29a20f52be0f2ca54992b492c54e0076b", 10 | "version": "0.5.3" 11 | } 12 | }, 13 | { 14 | "package": "swift-case-paths", 15 | "repositoryURL": "https://github.com/pointfreeco/swift-case-paths", 16 | "state": { 17 | "branch": null, 18 | "revision": "ce9c0d897db8a840c39de64caaa9b60119cf4be8", 19 | "version": "0.8.1" 20 | } 21 | }, 22 | { 23 | "package": "swift-collections", 24 | "repositoryURL": "https://github.com/apple/swift-collections", 25 | "state": { 26 | "branch": null, 27 | "revision": "48254824bb4248676bf7ce56014ff57b142b77eb", 28 | "version": "1.0.2" 29 | } 30 | }, 31 | { 32 | "package": "swift-composable-architecture", 33 | "repositoryURL": "https://github.com/pointfreeco/swift-composable-architecture", 34 | "state": { 35 | "branch": null, 36 | "revision": "2828dc44f6e3f81d84bcaba72c1ab1c0121d66f6", 37 | "version": "0.34.0" 38 | } 39 | }, 40 | { 41 | "package": "swift-custom-dump", 42 | "repositoryURL": "https://github.com/pointfreeco/swift-custom-dump", 43 | "state": { 44 | "branch": null, 45 | "revision": "c4f78db9b90ca57b7b6abc2223e235242739ea3c", 46 | "version": "0.4.0" 47 | } 48 | }, 49 | { 50 | "package": "swift-identified-collections", 51 | "repositoryURL": "https://github.com/pointfreeco/swift-identified-collections", 52 | "state": { 53 | "branch": null, 54 | "revision": "680bf440178a78a627b1c2c64c0855f6523ad5b9", 55 | "version": "0.3.2" 56 | } 57 | }, 58 | { 59 | "package": "xctest-dynamic-overlay", 60 | "repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay", 61 | "state": { 62 | "branch": null, 63 | "revision": "50a70a9d3583fe228ce672e8923010c8df2deddd", 64 | "version": "0.2.1" 65 | } 66 | } 67 | ] 68 | }, 69 | "version": 1 70 | } 71 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "composable-open-url", 8 | platforms: [ 9 | .iOS(.v13), 10 | .macOS(.v10_15), 11 | .tvOS(.v13), 12 | .watchOS(.v6), 13 | ], 14 | products: [ 15 | .library( 16 | name: "ComposableOpenURL", 17 | targets: ["ComposableOpenURL"]), 18 | ], 19 | dependencies: [ 20 | .package( 21 | url: "https://github.com/pointfreeco/swift-composable-architecture", 22 | from: "0.34.0" 23 | ), 24 | ], 25 | targets: [ 26 | .target( 27 | name: "ComposableOpenURL", 28 | dependencies: [ 29 | .product(name: "ComposableArchitecture", package: "swift-composable-architecture") 30 | ]), 31 | .testTarget( 32 | name: "ComposableOpenURLTests", 33 | dependencies: ["ComposableOpenURL"]), 34 | ] 35 | ) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComposableOpenURL 2 | 3 | [![CI](https://github.com/Shimmur/composable-open-url/actions/workflows/ci.yml/badge.svg)](https://github.com/Shimmur/composable-open-url/actions/workflows/ci.yml) 4 | 5 | **Note:** This library is no longer maintained - you should use the built-in `openURL` effect that comes with `swift-dependencies`. 6 | 7 | ## State-driven URL opening for The Composable Architecture 8 | 9 | ComposableOpenURL is a standalone component designed to be used with the [The Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture). 10 | 11 | It comprises of a high-level reducer and a SwiftUI view modifier that you can use to embed state-driven URL opening behaviour in your own app's feature domains. 12 | 13 | ## What’s the problem this solves? 14 | 15 | There are a number of ways to open external URLs. UIKit provides `UIApplication.shared.open` and iOS 14/macOS provides `OpenURLAction` which can be accessed from the SwiftUI Environment using the `\.openURL` environment key. In addition to this, on macOS 11/iOS 14 etc. there is the SwiftUI `Link` component. 16 | 17 | For very simple use cases where you just want to display a link to some external URL then `Link` (or a `Button` if you need to support older platforms) is absolutely fine and probably what you need in a lot of cases. You can’t easily write an automated test for it but that might be an acceptable trade-off if you’re literally just opening some fixed external URL. 18 | 19 | Sometimes however, you want to be able to trigger the opening of a URL as a result of some store action - this could be an action you explicitly send from your view which triggers the URL opening (perhaps alongside some other behaviour), or it could be an action sent from a button in an alert or action sheet (using TCA’s `AlertState` and `ActionSheetState` components). It could also be an action sent as the result of an `Effect`. The URL could be dynamic, or computed based on some other part of your state. It could just be the case that you want to test the behaviour. 20 | 21 | In these cases it would be really useful to trigger an external URL opening from your reducer itself. 22 | 23 | ## An effect-based approach 24 | 25 | One way to implement this is to treat the opening of an external URL as an `Effect`. This is probably a reasonable approach as it does feel like a side-effect. You could probably implement it something like this: 26 | 27 | ```swift 28 | struct FeatureEnvironment { 29 | var openURL: (URL) -> Effect 30 | } 31 | 32 | enum FeatureAction { 33 | case tappedOpenURLButton 34 | } 35 | 36 | let featureReducer = Reducer { state, action environment in 37 | switch action { 38 | case .tappedOpenURLButton: 39 | return environment 40 | .openURL("http://example.com") 41 | .fireAndForget() 42 | } 43 | } 44 | ``` 45 | 46 | Whilst this fairly straightforward and not a lot of code, it does have some downsides: 47 | 48 | * You need to pass around the `openURL` dependency to every feature that needs to be able to open a URL (you could potentially address this using the `SystemEnvironment` idea in the TCA examples folder but its still a fair amount of boilerplate). 49 | * Testing fire-and-forget effects is not the most ergonomic and often requires some kind of mock dependency with some mutable local state that you assert on in a `.do` block, e.g.: 50 | 51 | ```swift 52 | var openedURL: URL? 53 | 54 | let store = TestStore( 55 | initialState: ..., 56 | reducer: ..., 57 | environment: FeatureEnvironment( 58 | openURL: { url in openedURL = url } 59 | ) 60 | ) 61 | 62 | store.assert( 63 | .send(.tappedOpenURLButton), 64 | .do { _ in 65 | XCTAssertEqual(.some("http://example.com"), openedURL) 66 | } 67 | ) 68 | ``` 69 | 70 | For these reasons, inspired by the existing `TextState`, `AlertState` and `ActionSheetState` components this library takes a more state-base approach. 71 | 72 | ## State-based URL opening 73 | 74 | The way this component works is around a feature domain based on a single value of type `URL?` - the idea is that you have some URL property in your feature domain that you set to a value you need opening and it just opens. Conceptually, the feature is saying “this is the URL that should be opened” and the actual effect of opening it in whatever external application should handle it is handled entirely in the view layer, using a SwiftUI view modifier, as a result of the state change. 75 | 76 | There are a number of advantages to this approach: 77 | 78 | * Minimal boilerplate - just three lines of code to integrate the URL opening domain into your feature domain, and a single SwiftUI view modifier to attach the URL opening behaviour to your view. 79 | * Opening a URL is a one-line state mutation and you don’t even need to take care of setting it back to `nil` again once the URL has been opened as the component handles it for you. 80 | * Easy to test - its just a state mutation so you can test this like any other state mutation using `TestStore`. 81 | * You can directly hook into the OpenURL actions in your own feature reducer if you need to perform some additional logic or handle URLs that cannot be opened. 82 | 83 | So with all this said, what does it actually look like? Lets adapt the previous example to use the new component. 84 | 85 | Firstly you need to embed the URL opening domain in your feature domain: 86 | 87 | ```swift 88 | import ComposableArchitecture 89 | import ComposableOpenURL 90 | 91 | struct FeatureState { 92 | var urlToOpen: URL? // 1. An optional URL property 93 | } 94 | 95 | enum FeatureAction { 96 | case tappedOpenURLButton 97 | case openURL(OpenURLViewAction) // 2. Embed the component domain actions 98 | } 99 | 100 | let featureReducer = Reducer { state, action, _ in 101 | switch action { 102 | case .tappedOpenURLButton: 103 | state.urlToOpen = URL(string: "http://example.com") // 3. Set the URL when you want to open it 104 | } 105 | } 106 | .opensURL( // 4. Attach the component's high-level reducer 107 | \FeatureState.urlToOpen, 108 | action: /FeatureAction.openURL 109 | ) 110 | ``` 111 | 112 | Next, you need to attach the view modifier to our view and hand it a store scoped to the URL state that you want to open: 113 | 114 | ```swift 115 | struct FeatureView: View { 116 | let store: Store 117 | 118 | var body: some View { 119 | WithViewStore(store) { viewStore in 120 | Button("Open URL") { 121 | viewStore.send(.tappedOpenURLButton) 122 | } 123 | } 124 | .opensURL( 125 | store.scope( 126 | state: \.urlToOpen, 127 | action: FeatureAction.openURL 128 | ) 129 | ) 130 | } 131 | } 132 | ``` 133 | 134 | And that’s it! 135 | 136 | You can test this behaviour, including simulating the URL actually being opened, without the need for any mocks: 137 | 138 | ```swift 139 | class FeatureTests: XCTestCase { 140 | func testOpeningURL() { 141 | let store = TestStore( 142 | initialState: FeatureState(), 143 | reducer: featureReducer, 144 | environment: () 145 | ) 146 | 147 | store.assert( 148 | .send(.tappedOpenURLButton) { 149 | $0.urlToOpen = "http://example.com" 150 | }, 151 | .send(.openURL(.openedURL)) { 152 | $0.urlToOpen = nil 153 | } 154 | ) 155 | } 156 | } 157 | ``` 158 | 159 | No mocks, no dependencies, no mutable local state and no raw assertions in `.do` blocks. 160 | 161 | ## Copyright and License 162 | 163 | This library was developed out of the work on our app here at [Community.com](http://community.com) and is made available under the [Apache 2.0 license](LICENSE). 164 | 165 | ``` 166 | Copyright 2021 Community.com, Inc. 167 | 168 | Licensed under the Apache License, Version 2.0 (the "License"); 169 | you may not use this file except in compliance with the License. 170 | You may obtain a copy of the License at 171 | 172 | http://www.apache.org/licenses/LICENSE-2.0 173 | 174 | Unless required by applicable law or agreed to in writing, software 175 | distributed under the License is distributed on an "AS IS" BASIS, 176 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 177 | See the License for the specific language governing permissions and 178 | limitations under the License. 179 | ``` 180 | -------------------------------------------------------------------------------- /Sources/ComposableOpenURL/OpenURL.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Community.com, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #if !os(macOS) 16 | import ComposableArchitecture 17 | import CasePaths 18 | import SwiftUI 19 | import UIKit 20 | 21 | public extension Reducer where State: Equatable { 22 | /// Attaches the `opensURL` logic to your existing feature reducer, returning a new reducer. 23 | /// 24 | /// Can be used in conjunction with the `.opensURL` view modifier to automatically open 25 | /// external URLs driven by your application state. 26 | /// 27 | /// To use this high-level reducer, you first need to embed it into your feature. This requires: 28 | /// 29 | /// * A `URL?` property on your state that represents the URL you want to open. 30 | /// * An action in your feature's action enum that wraps `OpenURLViewAction` 31 | /// 32 | /// For example, given the following domain: 33 | /// 34 | /// struct FeatureState: Equatable { 35 | /// var urlToOpen: URL? 36 | /// } 37 | /// 38 | /// enum FeatureAction: Equatable { 39 | /// case tappedOpenLinkButton 40 | /// case openURL(OpenURLViewAction) 41 | /// } 42 | /// 43 | /// You can then attach the open URL reducer to your feature's reducer, providing a key path 44 | /// to the URL and a case path for the action: 45 | /// 46 | /// let featureReducer = Reducer { state, action in 47 | /// switch action { 48 | /// case .tappedOpenLinkButton: 49 | /// state.urlToOpen = URL(string: "http://www.example.com") 50 | /// return .none 51 | /// case .openURL: 52 | /// return .none 53 | /// } 54 | /// } 55 | /// .opensURL(\.urlToOpen, action: /FeatureAction.openURL) 56 | /// 57 | /// The above reducer will set the URL to be opened when the feature's view sends the `tappedOpenLinkButton`. 58 | /// 59 | /// To actually open the URL, the corresponding feature view needs to use the `.opensURL` view modifier, passing 60 | /// in a store scoped to the `URL` state and `OpenURLViewAction` action: 61 | /// 62 | /// struct FeatureView: View { 63 | /// let store: Store 64 | /// 65 | /// var body: some View { 66 | /// WithViewStore(store) { viewStore in 67 | /// Button("Open example.com") { 68 | /// viewStore.send(.tappedOpenLinkButton) 69 | /// } 70 | /// } 71 | /// .opensURL( 72 | /// store.scope( 73 | /// state: \.urlToOpen, 74 | /// action: /FeatureAction.openURL 75 | /// ) 76 | /// ) 77 | /// } 78 | /// } 79 | /// 80 | /// Now, when the `urlToOpen` property is set to a `URL` value, it will automatically open and fire an action 81 | /// back into the store to indicate it was opened, which will set the `urlToOpen` property back to `nil`. 82 | /// 83 | /// - Note: A check will be made before attempting to open the URL that opening that URL is supported - if not, the action 84 | /// `OpenURLViewAction.urlNotSupported` will be sent to the store. 85 | /// 86 | /// You can handle this action in your own feature reducer if you want to provide some kind of fallback option. 87 | /// 88 | /// - Parameters: 89 | /// - state: a key path to the URL that should be opened. 90 | /// - action: the `CasePath` to the action that embeds the `OpenURLViewAction` in your domain. 91 | /// 92 | func opensURL( 93 | state: WritableKeyPath, 94 | action: CasePath 95 | ) -> Self { 96 | Reducer { state, action, _ in 97 | switch action { 98 | case .openedURL, .urlNotSupported: 99 | state = nil 100 | return .none 101 | } 102 | } 103 | .pullback( 104 | state: state, 105 | action: action, 106 | environment: { _ in () } 107 | ) 108 | .combined(with: self) 109 | } 110 | } 111 | 112 | /// Represents the domain of opening URLs and can be embedded in your feature domain actions. 113 | /// 114 | public enum OpenURLViewAction: Equatable { 115 | /// Sent by the component to the store to indicate if URL was opened. 116 | case openedURL(Bool) 117 | 118 | /// Indicates the URL given cannot be opened on this platform. 119 | case urlNotSupported 120 | } 121 | 122 | @available(macOS, unavailable) 123 | private struct OpenURLViewModifier: ViewModifier { 124 | let store: Store 125 | let viewStore: ViewStore 126 | 127 | init(store: Store) { 128 | self.store = store 129 | viewStore = ViewStore(store) 130 | } 131 | 132 | func body(content: Content) -> some View { 133 | // There appears to be a bug with `.onReceive` in a ViewModifier, 134 | // where it doesn't seem to fire correctly unless you append the 135 | // `.onAppear()` modifier first. 136 | content.onAppear().onReceive(viewStore.publisher) { newValue in 137 | if let url = newValue { 138 | if self.canOpenURL(url) { 139 | self.openURL(url) { self.viewStore.send(.openedURL($0)) } 140 | } else { 141 | self.viewStore.send(.urlNotSupported) 142 | } 143 | } 144 | } 145 | } 146 | 147 | private func openURL(_ url: URL, completion: @escaping (Bool) -> Void) { 148 | if #available(iOS 14, macCatalyst 14, tvOS 14, *) { 149 | URLOpener_OpenURLAction(url: url).open(completion: completion) 150 | } else { 151 | URLOpener_UIApplication(url: url).open(completion: completion) 152 | } 153 | } 154 | 155 | private func canOpenURL(_ url: URL) -> Bool { 156 | UIApplication.shared.canOpenURL(url) 157 | } 158 | 159 | struct URLOpener_UIApplication { 160 | let url: URL 161 | 162 | func open(completion: @escaping (Bool) -> Void) { 163 | UIApplication.shared.open(url, completionHandler: completion) 164 | } 165 | } 166 | 167 | @available(iOS 14, *) 168 | @available(macCatalyst 14, *) 169 | @available(tvOS 14, *) 170 | struct URLOpener_OpenURLAction { 171 | let url: URL 172 | 173 | @Environment(\.openURL) var openURL 174 | 175 | func open(completion: @escaping (Bool) -> Void) { 176 | openURL(url, completion: completion) 177 | } 178 | } 179 | } 180 | 181 | public extension View { 182 | /// Attaches automatic URL opening behaviour to your view. 183 | /// 184 | /// This will attach a view modifier to your view that observes the `URL` state on the provided store and 185 | /// automatically opens it when the `URL` becomes non-nil, before dispatching an action back to the store 186 | /// to indicate the URL was opened and reset the `URL` back to `nil`. 187 | /// 188 | /// - Parameters: 189 | /// - store: A store scoped to the `URL` and `OpenURLViewAction` embedded in your feature domain. 190 | /// 191 | func opensURL(_ store: Store) -> some View { 192 | modifier(OpenURLViewModifier(store: store)) 193 | } 194 | } 195 | #endif 196 | -------------------------------------------------------------------------------- /Tests/ComposableOpenURLTests/ComposableOpenURLTests.swift: -------------------------------------------------------------------------------- 1 | #if !os(macOS) 2 | import XCTest 3 | import ComposableOpenURL 4 | import ComposableArchitecture 5 | 6 | class OpenURLTests: XCTestCase { 7 | struct AppState: Equatable { 8 | var url: URL? 9 | } 10 | 11 | enum AppAction: Equatable { 12 | case tappedToOpen 13 | case openURL(OpenURLViewAction) 14 | } 15 | 16 | let store = TestStore( 17 | initialState: AppState(), 18 | reducer: Reducer { state, action, _ in 19 | switch action { 20 | case .tappedToOpen: 21 | state.url = URL(string: "http://example.com") 22 | return .none 23 | case .openURL: 24 | return .none 25 | } 26 | }.opensURL( 27 | state: \.url, 28 | action: /AppAction.openURL 29 | ), 30 | environment: () 31 | ) 32 | 33 | func testOpeningSupportedURL() { 34 | store.send(.tappedToOpen) { 35 | $0.url = URL(string: "http://example.com") 36 | } 37 | store.send(.openURL(.openedURL(true))) { 38 | $0.url = nil 39 | } 40 | } 41 | 42 | func testOpeningUnsupportedURL() { 43 | store.send(.tappedToOpen) { 44 | $0.url = URL(string: "http://example.com") 45 | } 46 | store.send(.openURL(.urlNotSupported)) { 47 | $0.url = nil 48 | } 49 | } 50 | 51 | func testOpeningURLFails() { 52 | store.send(.tappedToOpen) { 53 | $0.url = URL(string: "http://example.com") 54 | } 55 | store.send(.openURL(.openedURL(true))) { 56 | $0.url = nil 57 | } 58 | } 59 | } 60 | #endif 61 | --------------------------------------------------------------------------------