MatchaTea 0.4.0

MatchaTea 0.4.0

Kyohei Ito维护。



MatchaTea 0.4.0

  • Kyohei Ito

🍵Matcha

Carthage compatible Build Status codecov Version License Platform

什么是Matcha?

Matcha是一个框架,可以从URL路径获取参数。它没有Router,所以很简洁。

它可以像以下这样使用

let url = URL(string: "https://example.com/user/1/settings")!
let matcha = Matcha(url: url, pattern: "/user/{userID}/settings")
matcha?.value(of: "userID")     // "1"
matcha?.value(at: 0)            // "1"

要求

  • Swift 5.0

如何安装

CocoaPods

将以下内容添加到您的Podfile

pod "MatchaTea"

⚠️ 警告:如果您想从CocoaPods安装,必须将MatchaTea添加到Podfile中,因为有一个不同于此的Matcha

Carthage

将以下内容添加到您的Cartfile

github "cats-oss/Matcha"

如何使用Matcha

如果您已经知道了URL路径信息,可以使用该模式创建实例。

let url = URL(string: "https://example.com/user/1/settings")!
let matcha = Matcha(url: url, pattern: "/user/{userID}/settings")

然后,可以获取匹配的值。

matcha?.value(of: "userID")     // "1"
matcha?.value(at: 0)            // "1"
matcha?["userID"]               // "1"
matcha?[0]                      // "1"

如果不知道URL路径的任何信息,请在使用URL创建实例后匹配模式。

if let url = url {
    let matcha = Matcha(url: url)
    if matcha.matched("/") != nil {
        // to root
    } else if matcha.matched("/notification") != nil {
        // to notification
    } else if let id = matcha.matched("/user/{userID}")?["userID"] {
        // to user with id
    }
}

许可信息

根据MIT许可。详见LICENSE文件。