PathTo

1.1.0

A lightweight Swift path pattern matcher for URL-style routing — supports named parameters, optional segments, and splat wildcards.
jaywcjlove/swift-path-to

What's New

v1.1.0

2025-12-02T05:51:56Z

Full Changelog: v1.0.0...v1.1.0

Using my app is also a way to support me:
Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Mousio Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe

PathTo

A lightweight Swift path pattern matcher for URL-style routing — supports named parameters, optional segments, and splat wildcards.

Installation

Swift Package Manager

Add CodeMirror to your project using Xcode:

  1. In Xcode, go to FileAdd Package Dependencies...
  2. Enter the repository URL: https://github.com/jaywcjlove/swift-path-to.git
  3. Click Add Package

Or add it to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/jaywcjlove/swift-path-to.git", from: "1.0.0")
]

Features

  • Named parameters: :name captures a single path segment.
  • Optional segments: {/:id} marks a single segment as optional.
  • Splat/wildcard: *rest captures remaining segments into an array.

Usage

import PathTo

Parameters

Parameters match arbitrary strings in a path by matching up to the end of a segment or up to any subsequent tokens. They are defined by prefixing the parameter name with a colon (:foo).

let fn = PathTo.match("/:foo/:bar")

if let r = fn("/test/route") {
    // r -> params: ["foo": "test", "bar": "route"]
    print(r.path) // "/test/route"
    print(r.params["foo"] as? String) // "test"
    print(r.params["bar"] as? String) // "route"
}

Wildcard

Wildcard parameters match one or more characters across multiple segments. They are defined the same way as regular parameters, but are prefixed with an asterisk (*foo).

let fn = PathTo.match("/*splat")
if let r2 = fn("/bar/baz") {
    // r -> params: ["splat": ["bar", "baz"]]
    print(r2.params["splat"] as? [String]) // ["bar", "baz"]
}

Optional

Braces can be used to define parts of the path that are optional.

let fn = PathTo.match("/users{/:id}/delete")
print(fn("/users/delete")?.params) // [:]
print(fn("/users/123/delete")?.params) // ["id": "123"]

License

Licensed under the MIT License.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Apr 23 2026 00:15:26 GMT-0900 (Hawaii-Aleutian Daylight Time)