From 4c80529bed87296361a517061e4640195d23e918 Mon Sep 17 00:00:00 2001 From: Eliah Snakin Date: Mon, 20 Jan 2020 15:08:41 +0300 Subject: [PATCH] cocoapods release 1.0-alpha fixes --- .../project.pbxproj | 8 ++-- .../logo-monarch.imageset/Contents.json | 3 ++ .../Base.lproj/Main.storyboard | 16 +++---- Source/Request.swift | 2 +- Source/Route.swift | 2 +- Source/String+extension.swift | 47 +++++++++++++++++++ 6 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 Source/String+extension.swift diff --git a/Example/MonarchRouterExample.xcodeproj/project.pbxproj b/Example/MonarchRouterExample.xcodeproj/project.pbxproj index fe20b09..a0891f8 100644 --- a/Example/MonarchRouterExample.xcodeproj/project.pbxproj +++ b/Example/MonarchRouterExample.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 17958E51AD3E4032D5A6C478 /* Pods_MonarchRouter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CF23C904D963434DC0360A9D /* Pods_MonarchRouter.framework */; }; 9187C6D64BB2763E78C00E8D /* Pods_MonarchRouterExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1907EB298DF999B25DA1BB67 /* Pods_MonarchRouterExample.framework */; }; D03164B7237B8C9300F9B1EC /* Route.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03164B6237B8C9300F9B1EC /* Route.swift */; }; - D03164B9237BA5D300F9B1EC /* String+extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03164B8237BA5D300F9B1EC /* String+extension.swift */; }; D03164BB237E1C3A00F9B1EC /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03164BA237E1C3A00F9B1EC /* Request.swift */; }; D07E7B0C21A5606F00B415D6 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07E7B0B21A5606F00B415D6 /* State.swift */; }; D09228CC235B4AB30066E33B /* AppRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = D09228CB235B4AB30066E33B /* AppRoutes.swift */; }; @@ -32,6 +31,7 @@ D0A7BA12219F378B00B44C3D /* Presenters.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A7BA11219F378B00B44C3D /* Presenters.swift */; }; D0A7BA14219F3C5900B44C3D /* EndpointBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A7BA13219F3C5800B44C3D /* EndpointBuilder.swift */; }; D0A7BA16219F3EC500B44C3D /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A7BA15219F3EC500B44C3D /* AppCoordinator.swift */; }; + D0D1F2E223D5CF2C00EFB61F /* String+extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0D1F2E123D5CF2C00EFB61F /* String+extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -66,7 +66,6 @@ 9E40EA1D4799DD2D0F3A8810 /* Pods-MonarchRouterExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MonarchRouterExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MonarchRouterExample/Pods-MonarchRouterExample.debug.xcconfig"; sourceTree = ""; }; CF23C904D963434DC0360A9D /* Pods_MonarchRouter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MonarchRouter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D03164B6237B8C9300F9B1EC /* Route.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Route.swift; path = ../../Source/Route.swift; sourceTree = ""; }; - D03164B8237BA5D300F9B1EC /* String+extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+extension.swift"; sourceTree = ""; }; D03164BA237E1C3A00F9B1EC /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Request.swift; path = ../../Source/Request.swift; sourceTree = ""; }; D07E7B0B21A5606F00B415D6 /* State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = State.swift; path = ../../Source/State.swift; sourceTree = ""; }; D09228CB235B4AB30066E33B /* AppRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRoutes.swift; sourceTree = ""; }; @@ -90,6 +89,7 @@ D0A7BA11219F378B00B44C3D /* Presenters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Presenters.swift; sourceTree = ""; }; D0A7BA13219F3C5800B44C3D /* EndpointBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndpointBuilder.swift; sourceTree = ""; }; D0A7BA15219F3EC500B44C3D /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; + D0D1F2E123D5CF2C00EFB61F /* String+extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "String+extension.swift"; path = "../../Source/String+extension.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -183,7 +183,7 @@ D09D0DF021A4703100601258 /* PresenterFork.swift */, D09D0DF221A470C300601258 /* PresenterSwitcher.swift */, D0A7BA0B219F363900B44C3D /* Collection+extension.swift */, - D03164B8237BA5D300F9B1EC /* String+extension.swift */, + D0D1F2E123D5CF2C00EFB61F /* String+extension.swift */, D0A7B9EC219F324200B44C3D /* MonarchRouter.h */, D0A7B9ED219F324200B44C3D /* Info.plist */, ); @@ -382,9 +382,9 @@ D03164B7237B8C9300F9B1EC /* Route.swift in Sources */, D09D0DF321A470C300601258 /* PresenterSwitcher.swift in Sources */, D09D0DEF21A46FE300601258 /* PresenterStack.swift in Sources */, + D0D1F2E223D5CF2C00EFB61F /* String+extension.swift in Sources */, D03164BB237E1C3A00F9B1EC /* Request.swift in Sources */, D09D0DF121A4703100601258 /* PresenterFork.swift in Sources */, - D03164B9237BA5D300F9B1EC /* String+extension.swift in Sources */, D0A7BA10219F363900B44C3D /* Node.swift in Sources */, D09228D2235B5CFC0066E33B /* Parameters.swift in Sources */, D0A7BA0E219F363900B44C3D /* Collection+extension.swift in Sources */, diff --git a/Example/MonarchRouterExample/Assets.xcassets/logo-monarch.imageset/Contents.json b/Example/MonarchRouterExample/Assets.xcassets/logo-monarch.imageset/Contents.json index 10cbec7..fb1346b 100644 --- a/Example/MonarchRouterExample/Assets.xcassets/logo-monarch.imageset/Contents.json +++ b/Example/MonarchRouterExample/Assets.xcassets/logo-monarch.imageset/Contents.json @@ -17,5 +17,8 @@ "info" : { "version" : 1, "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "original" } } \ No newline at end of file diff --git a/Example/MonarchRouterExample/Base.lproj/Main.storyboard b/Example/MonarchRouterExample/Base.lproj/Main.storyboard index c0f7714..8627b87 100644 --- a/Example/MonarchRouterExample/Base.lproj/Main.storyboard +++ b/Example/MonarchRouterExample/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -102,7 +102,7 @@ - + @@ -173,7 +173,7 @@ - + @@ -252,7 +252,7 @@ - + @@ -331,7 +331,7 @@ - + @@ -399,7 +399,7 @@ - + @@ -462,7 +462,7 @@ - + diff --git a/Source/Request.swift b/Source/Request.swift index ce25750..37d8d0c 100644 --- a/Source/Request.swift +++ b/Source/Request.swift @@ -22,7 +22,7 @@ extension URL: RoutingRequestType public func resolve(for route: RouteType) -> RoutingResolvedRequestType { let pathComponents: [PathComponentType] = self.pathComponents.enumerated().map { (i, pathComponent) in - if route.components.count > i, case .parameter(let name, let parameterType, _) = route.components[i] { + if route.components.count > i, case .parameter(let name, _, _) = route.components[i] { return PathParameter(name, pathComponent) } diff --git a/Source/Route.swift b/Source/Route.swift index 9352e6c..ba04a99 100644 --- a/Source/Route.swift +++ b/Source/Route.swift @@ -24,7 +24,7 @@ public enum RouteComponent guard let pathComponent = pathComponent as? PathConstant else { return false } return pathComponent.name == name - case .parameter(let name, let parameterType, let isMatching): + case .parameter(let name, _ /*let parameterType*/, let isMatching): // path component is not a parameter guard let pathComponent = pathComponent as? PathParameterType else { return false } diff --git a/Source/String+extension.swift b/Source/String+extension.swift new file mode 100644 index 0000000..040344b --- /dev/null +++ b/Source/String+extension.swift @@ -0,0 +1,47 @@ +// +// String+extension.swift +// MonarchRouter +// +// Created by Eliah Snakin on 13.11.2019. +// Copyright © 2019 nikans.com. All rights reserved. +// + +import Foundation + + + +// A set of operations for parametrized routes handling. +extension String +{ + /// Returns whether a String matches a given regex. + func matches(_ regex: String) -> Bool { + return self.range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil + } + + /// Returns substrings captured by regex groups. + func capturedGroups(withRegex pattern: String) -> [String] { + var results = [String]() + + var regex: NSRegularExpression + do { + regex = try NSRegularExpression(pattern: pattern, options: []) + } catch { + return results + } + + let matches = regex.matches(in: self, options: [], range: NSRange(location:0, length: count)) + + guard let match = matches.first else { return results } + + let lastRangeIndex = match.numberOfRanges - 1 + guard lastRangeIndex >= 1 else { return results } + + for i in 1...lastRangeIndex { + let capturedGroupIndex = match.range(at: i) + let matchedString = (self as NSString).substring(with: capturedGroupIndex) + results.append(matchedString) + } + + return results + } +}