Skip to content

Commit

Permalink
URLProtocol => URLCoin
Browse files Browse the repository at this point in the history
  • Loading branch information
linhay committed Mar 6, 2018
1 parent 1f7b62c commit 497fb08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SPRoutable.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SPRoutable'
s.version = '0.9.1'
s.version = '0.9.2'
s.summary = '基础的路由服务'


Expand Down
6 changes: 3 additions & 3 deletions Sources/URLProtocol.swift → Sources/Routable+URLCoin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import Foundation

public protocol URLProtocol {
public protocol URLCoin {
func asURL() -> URL?
func asString() -> String
}


extension String: URLProtocol {
extension String: URLCoin {
public func asURL() -> URL? {
guard let url = URL(string: self) else {
assert(false, "检查 url: " + self)
Expand All @@ -27,7 +27,7 @@ extension String: URLProtocol {
}
}

extension URL: URLProtocol {
extension URL: URLCoin {

public func asURL() -> URL? {
return self
Expand Down
14 changes: 7 additions & 7 deletions Sources/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public extension Routable {
///
/// - Parameter url: viewController 路径
/// - Returns: viewController 或者 nil
public static func viewController(url: URLProtocol,params:[String: Any] = [:]) -> UIViewController? {
public static func viewController(url: URLCoin,params:[String: Any] = [:]) -> UIViewController? {
if let vc = object(url: url, params: params) as UIViewController? { return vc }
return nil
}


public static func object(url: URLProtocol, params:[String: Any] = [:], call: @escaping (_: [String: Any])->()) {
public static func object(url: URLCoin, params:[String: Any] = [:], call: @escaping (_: [String: Any])->()) {
guard let path = urlFormat(url: url, params: params) else { return }
guard let value = getPathValues(url: path) else { return }
let id = "blockCache\(blockCache.count)"
Expand All @@ -60,7 +60,7 @@ public extension Routable {
///
/// - Parameter url: view 路径
/// - Returns: view 或者 nil
public static func view(url: URLProtocol,params:[String: Any] = [:]) -> UIView? {
public static func view(url: URLCoin,params:[String: Any] = [:]) -> UIView? {
if let vc = object(url: url, params: params) as UIView? { return vc }
return nil
}
Expand All @@ -69,7 +69,7 @@ public extension Routable {
///
/// - Parameter url: view 路径
/// - Returns: view 或者 nil
public static func object<T: Any>(url: URLProtocol,params:[String: Any] = [:]) -> T? {
public static func object<T: Any>(url: URLCoin,params:[String: Any] = [:]) -> T? {
guard let path = urlFormat(url: url, params: params) else { return nil }
guard let value = getPathValues(url: path) else { return nil }
guard let result = target(name: value.class, actionName: value.function, params: value.params) else { return nil }
Expand All @@ -87,7 +87,7 @@ public extension Routable {
/// 通知所有已缓存类型函数
///
/// - Parameter url: 函数路径
public static func notice(url: URLProtocol,params:[String: Any] = [:]) {
public static func notice(url: URLCoin,params:[String: Any] = [:]) {
guard let path = urlFormat(url: url, params: params) else { return }
if path.host != "notice" {
assert(false, "检查 URL host: " + (path.host ?? "") + "🌰: http://notice/path")
Expand All @@ -108,7 +108,7 @@ public extension Routable {
/// 执行路径指定函数
///
/// - Parameter url: 函数路径
public static func executing(url: URLProtocol, params:[String: Any] = [:]) {
public static func executing(url: URLCoin, params:[String: Any] = [:]) {
_ = object(url: url, params: params) as Any?
}

Expand All @@ -124,7 +124,7 @@ public extension Routable {
cache.removeValue(forKey: targetName)
}

public static func urlFormat(url: URLProtocol,params:[String: Any]) -> URL?{
public static func urlFormat(url: URLCoin,params:[String: Any]) -> URL?{
if params.isEmpty { return url.asURL() }
guard var components = URLComponents(string: url.asString()) else { return nil }
var querys = components.queryItems ?? []
Expand Down

0 comments on commit 497fb08

Please sign in to comment.