All Projects → johnpatrickmorgan → URLPatterns

johnpatrickmorgan / URLPatterns

Licence: MIT license
A small library to enable more idiomatic Swift pattern matching of URL path elements.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to URLPatterns

SwiftDown
📦 A themable markdown editor component for your SwiftUI apps.
Stars: ✭ 203 (+298.04%)
Mutual labels:  spm
SwiftyPods
Type safe pods
Stars: ✭ 15 (-70.59%)
Mutual labels:  spm
YMFF
Feature management made easy.
Stars: ✭ 26 (-49.02%)
Mutual labels:  spm
CircularProgressView
Circular and animated progress bar for iOS
Stars: ✭ 25 (-50.98%)
Mutual labels:  spm
TIFeedParser
RSS Parser written in Swift
Stars: ✭ 18 (-64.71%)
Mutual labels:  spm
ecs-demo
Minimal demo App for the Fireblade Entity-Component System (ECS)
Stars: ✭ 20 (-60.78%)
Mutual labels:  spm
CSV
A simple CSV file parser and serializer
Stars: ✭ 31 (-39.22%)
Mutual labels:  spm
awesome-ios
A collaborative list of awesome for iOS developers. Include quick preview.
Stars: ✭ 1,329 (+2505.88%)
Mutual labels:  spm
Rocket
Define your release steps 🚀
Stars: ✭ 99 (+94.12%)
Mutual labels:  spm
OMJoystick
This is the JoyStick UI library for SwiftUI.
Stars: ✭ 15 (-70.59%)
Mutual labels:  spm
SwiftZip
Swift wrapper for libzip — library for reading, creating, and modifying zip archives.
Stars: ✭ 44 (-13.73%)
Mutual labels:  spm
trace-cocoa-sdk
Catch bugs before they reach production — get detailed crash reports and monitor how your app is performing across the entire install base.
Stars: ✭ 15 (-70.59%)
Mutual labels:  spm
BottomSheet
A BottomSheet component made with UIKit. Completely written in Swift 🧡
Stars: ✭ 62 (+21.57%)
Mutual labels:  spm
Match3Kit
Library for simple Match3 games.
Stars: ✭ 38 (-25.49%)
Mutual labels:  spm
mopass
A OpenSource Clientless & Serverless Password Manager
Stars: ✭ 40 (-21.57%)
Mutual labels:  spm
Table
CLI tables in Swift
Stars: ✭ 53 (+3.92%)
Mutual labels:  spm
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+35.29%)
Mutual labels:  spm
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (-50.98%)
Mutual labels:  spm
clinica
Software platform for clinical neuroimaging studies
Stars: ✭ 153 (+200%)
Mutual labels:  spm
danger-swift-xcodesummary
A Danger-Swift plugin that adds build errors, warnings and unit tests results generated from xcodebuild to your Danger report
Stars: ✭ 72 (+41.18%)
Mutual labels:  spm

🎯 URLPatterns 🎯

Version License Swift

URLPatterns is a small library to enable more idiomatic Swift pattern matching of URL path elements.

URL is extended with the method countedPathElements(), which converts the URL's' array of path elements into a Counted enum. Each case in Counted has a different number of associated values, which makes pattern-matching each element easy:

if case .n4("user", let userId, "profile", _) = url.countedPathElements() {
    // show profile for userId
}

Counted enables us to pattern match paths with any number of elements, and supports expression, wildcard and value-binding patterns for its associated values. It can match based on Begins and Ends, which match based on the first/ last elements only, and can even match a particular path element based on a regular expression. Here's an example of a DeepLink enum which has a failable initializer that takes a URL:

enum DeepLink {

    case home, history, settings, terms, news, contact
    case chat(room: String)
    case profile(userId: String)
}

extension DeepLink {

    init?(url: URL) {

        guard url.scheme == "myscheme" else { return nil }
        guard url.host == "myhost" else { return nil }

        switch url.countedPathComponents() {

        case .n0, .n1(""):                          self = .home
        case .n1("history"):                        self = .history
        case .n2(_, "settings"):                    self = .settings
        case .n2("chat", let room):                 self = .chat(room: room)
        case .n3("users", let userId, "profile"):   self = .profile(userId: userId)
        case .n1(Regex(contact.*))                  self = .contact
        case Begins("news", "latest"):              self = .news
        case Ends("terms"):                         self = .terms		
        default:                                    return nil
        }
    }
}

Installation

URLPatterns is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "URLPatterns"

License

URLPatterns is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].