ComposableDeepLink – 是一个 Swift DSL 库,用于以可组合和灵活的方式处理深层链接。
它提供了一种处理深层链接的方法,允许您使用更小组件的组合来定义复杂的深层链接处理逻辑。
您可以使用以下方式将 ComposableDeepLink 集成到您的项目中:
Package.swift
文件中.package(url: "https://github.com/xxKRASHxx/composable-deep-link", from: "0.2.0")
ComposableDeepLink
添加到您的 target 的依赖项中。这是一个简单的示例,演示如何使用 ComposableDeepLink 处理深层链接
import ComposableDeepLink // 1. Import Library
enum DeepLink { // 2. Define result type
case foo(id: String)
case bar
case biz
}
let processor = ComposableDeepLink<DeepLink> { // 3. Compose handling
Scheme("myapp") {
Host("example.host.com") {
Path("/foo/:id") { context in
Handle { // Handle the deep link logic here
guard let id = context.id else { return nil }
return .foo(id: id)
}
}
}
Host("another.host.com") {
Path("/bar") { context in
Handle { // Handle the deep link logic here
.bar
}
}
Path("/bar/biz") { context in
Handle { // Handle the deep link logic here
.biz
}
}
}
}
}
if let result = processor.handle(url: deepLinkURL) {
// 4. Do something with the result
}
欢迎贡献!
如果您有任何建议、功能请求或错误报告,请打开 issue 或提交 pull request
ComposableDeepLink 在 MIT 许可证下可用。
有关更多信息,请参阅 LICENSE 文件。