A simple path library written in Swift.
Add the following dependency to your
.package(url: "https://github.com/sersoft-gmbh/pathwrangler.git", from: "1.0.0"),
Or add it via Xcode (as of Xcode 11).
PathWrangler has two basic representations of a path:
RelativePath. They have everything you need for simple yet great path computations.
A relative path (as the name suggests) is not bound to any root. It's relative to whatever absolute path you need it to be. Thus it can also be turned into an absolute path using
An absolute path on the other hand is a path that always starts at the root.
Both paths know how to "resolve" (or "simplify") themselves. By doing so, they try to resolve and thus remove references of the current folder (
.) and parent folder (
..). Since absolute paths know where to start, they are even able to resolve symlinks. To do so, however, the path must exist on disk.
Both path implementations also have a
current accessor that returns the current path. For
AbsolutePath this is the
RelativePath this is always just the relative path to the current directory, thus
Path components or a relative path can be appended to both paths. There is even a convenience API that allows path building that almost looks like the path representation:
let someSubDir = AbsolutePath.root / "folder1" / "folder2" // -> "/folder1/folder2"
A protocol named
PathComponentConvertible is used to represent path components. A bunch of default conformances (like for
Int, etc.) make working with it easy. But adding more conformances is also easy. Just implement the only requirement
pathComponent and return the path component of the conforming type. As of then, the type can be used wherever path components are used in PathWrangler (like with the nice
/ API mentioned before).
The PathWrangler package contains two frameworks:
- One is
CorePathWranglerwhich contains all the underlying logic but has no dependency on Foundation whatsoever. It uses a few system APIs (like
getcwdfor determining the current working directory), but is otherwise mainly implemented in pure Swift using only stdlib types.
- The other one is
PathWranglerwhich adds a few neat APIs to
URLthat make interacting with
The API is documented using header doc. If you prefer to view the documentation as a webpage, there is an online version available for you.
If you find a bug / like to see a new feature in PathWrangler there are a few ways of helping out:
- If you can fix the bug / implement the feature yourself please do and open a PR.
- If you know how to code (which you probably do), please add a (failing) test and open a PR. We'll try to get your test green ASAP.
- If you can do neither, then open an issue. While this might be the easiest way, it will likely take the longest for the bug to be fixed / feature to be implemented.
See LICENSE file.
You may find interesting
v1.0.1 - 2020-03-25 11:22:21
Version 1.0.1 adds Swift 5.2 support
v1.0.0 - 2020-02-11 18:32:31
This is the initial release of PathWrangler, the simple yet powerful library for dealing with file system paths in Swift.
See the online documentation for more information on the API.