Skip to content

Commit ccfe818

Browse files
committed
Add URLPatternExample
1 parent 4debd21 commit ccfe818

12 files changed

Lines changed: 862 additions & 2 deletions

File tree

Sources/URLPatternClient/main.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ enum Deeplink {
1111

1212
@URLPath("/post/{id}")
1313
case nameDetailHI(id: String)
14+
15+
@URLPath("/home")
16+
case home
1417
}
1518

1619
let url1 = URL(string: "https://channel.io/post/12/12")
1720
let url2 = URL(string: "/post/hi/hello/hi/bye")
21+
let url3 = URL(string: "/home")
1822

1923
// enumPath
2024
// inputPath
@@ -29,4 +33,5 @@ let paths = url1!.pathComponents
2933

3034
print(Deeplink(url: url1!))
3135
print(Deeplink(url: url2!))
36+
print(Deeplink(url: url3!))
3237

Sources/URLPatternMacros/URLPathMacro.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ public struct URLPathMacro: PeerMacro {
107107
"""
108108
}
109109
}.joined(separator: "\n"))
110-
111-
return .\(raw: element.name.text)(\(raw: patternParams.map { "\($0.name): \($0.name)" }.joined(separator: ", ")))
110+
111+
return \(raw: patternParams.isEmpty
112+
? ".\(element.name.text)"
113+
: ".\(element.name.text)(\(patternParams.map { "\($0.name): \($0.name)" }.joined(separator: ", ")))")
112114
}
113115
""")
114116

0 commit comments

Comments
 (0)