美文网首页
Swift 获取URL字符串中对应字段的vaule

Swift 获取URL字符串中对应字段的vaule

作者: 烟雨痕 | 来源:发表于2019-01-21 14:07 被阅读7次
        工具类或者String分类中实现
       //获取url中对应的参数的值
        static func paramValueOfUrl(url: String, with param: String) -> String?  {
            guard let url = URLComponents.init(string: url) else { return nil }
            return url.queryItems?.first(where: {$0.name == param})?.value
        }
    
    使用:
    if  let articleId: String = MSFHelper.paramValueOfUrl(url: link, with: "id") {
            MSFArticleDetailVM.requestArticleDelete(with: Int(articleId) ?? 0, successClosure: { (result) in
            NotificationCenter.default.post(name: NSNotification.Name.deleteArticle,
                                                        object: nil,
                                                        userInfo: ["success": true, "errMsg": ""])
                    }) { (error) in
            NotificationCenter.default.post(name: NSNotification.Name.deleteArticle,
                                                        object: nil,
                                                        userInfo: ["success": false, "errMsg": error.errmsg])
                    }
                }
    

    相关文章

      网友评论

          本文标题:Swift 获取URL字符串中对应字段的vaule

          本文链接:https://www.haomeiwen.com/subject/wldcjqtx.html