Skip to content

Commit

Permalink
Merge pull request #12 from giginet/swift5
Browse files Browse the repository at this point in the history
Swift5
  • Loading branch information
giginet authored Apr 8, 2019
2 parents b2a02a7 + 6518460 commit 9ece0a4
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 62 deletions.
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode9.3
osx_image: xcode10.2
language: objective-c
install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
Expand All @@ -9,12 +9,5 @@ before_script:
matrix:
include:
- env: NAME=Xcode DESTINATION="platform=iOS Simulator,name=iPhone 8"
- env: NAME=SPM
script:
- |
if [ "$NAME" = "Xcode" ]
then
xcodebuild test -project Crossroad.xcodeproj -scheme Crossroad -destination "${DESTINATION}"
else
swift test
fi
- xcodebuild test -project Crossroad.xcodeproj -scheme Crossroad -destination "${DESTINATION}"
6 changes: 3 additions & 3 deletions Crossroad.podspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Pod::Spec.new do |s|
s.name = "Crossroad"
s.version = "1.0.1"
s.version = "2.0.0"
s.summary = "Route URL schemes easily"
s.description = <<-DESC
Crossroad is URL router focused on handling Custom URL Scheme.
Crossroad is an URL router focused on handling Custom URL Scheme.
Using this, you can route multiple URL schemes and fetch arguments and parameters easily.
DESC

Expand All @@ -15,5 +15,5 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/giginet/Crossroad.git", :tag => "#{s.version}" }
s.source_files = "Sources/Crossroad/**/*.{h,swift}"
s.requires_arc = true
s.swift_version = "4.1"
s.swift_version = "5.0"
end
18 changes: 10 additions & 8 deletions Crossroad.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = giginet;
TargetAttributes = {
546DEA7920AD77F800923325 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 0930;
LastSwiftMigration = 1020;
};
546DEA8220AD77F800923325 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1020;
};
};
};
Expand All @@ -193,6 +194,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 546DEA7020AD77F800923325;
productRefGroup = 546DEA7B20AD77F800923325 /* Products */;
Expand Down Expand Up @@ -383,7 +385,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
Expand All @@ -402,7 +404,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -411,7 +413,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
Expand All @@ -429,7 +431,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -450,7 +452,7 @@
PRODUCT_BUNDLE_IDENTIFIER = org.giginet.CrossroadTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -471,7 +473,7 @@
PRODUCT_BUNDLE_IDENTIFIER = org.giginet.CrossroadTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
26 changes: 0 additions & 26 deletions Package.swift

This file was deleted.

23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Crossroad](Documentation/logo.png)](https://github.com/giginet/Crossroad)

[![Build Status](https://travis-ci.org/giginet/Crossroad.svg?branch=master)](https://travis-ci.org/giginet/Crossroad)
[![Language](https://img.shields.io/badge/language-Swift%204.1-orange.svg)](https://swift.org)
[![Language](https://img.shields.io/badge/language-Swift%205-orange.svg)](https://swift.org)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Crossroad.svg)](http://cocoapods.org/pods/Crossroad)
[![Platform](https://img.shields.io/cocoapods/p/Crossroad.svg?style=flat)](http://cocoapods.org/pods/Crossroad)
Expand Down Expand Up @@ -52,7 +52,7 @@ router.register([
if !Pokedex.isExist(pokedexID) { // Find the Pokémon by ID
return false
}
presentPokedexDetailViewController(for: pokedexID)
presentPokedexDetailViewController(of: pokedexID)
return true
}),
// ...
Expand All @@ -64,10 +64,12 @@ router.openIfPossible(URL(string: "pokedex://pokemons/25")!) // Open Pikachu pag
router.openIfPossible(URL(string: "pokedex://pokemons?type=fire")!) // Open list of fire Pokémons page
```

You can also skip schemes on URLs. URLPattern `/search/:keyword` means `pokedex://search/:keyword` on the router.

In common use case, you should call `router.openIfPossible` on `UIApplicationDelegate` method.

```swift
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
return router.openIfPossible(url, options: options)
}
```
Expand All @@ -92,8 +94,6 @@ let generation: Int? = context.parameter(for: "generation") // 1

Currently supported type is `Int`, `Int64`, `Float`, `Double`, `Bool`, `String` and `URL`.

You can also skip schemes on URLs. URLPattern `/search/:keyword` means `pokedex://search/:keyword` on the router.

### Enum argument

You can use enum as arguments by implementing `Extractable`.
Expand All @@ -117,7 +117,7 @@ You can treat comma-separated query strings as `Array`.

```swift
// matches: pokedex://pokemons?types=water,grass
let types: [Type] = context.parameter(for: "types") // [.water, .grass]
let types: [Type]? = context.parameter(for: "types") // [.water, .grass]
```

### Custom argument
Expand Down Expand Up @@ -157,6 +157,17 @@ let userInfo = UserInfo(userID: User.current.id)
router.openIfPossible(url, userInfo: userInfo)
```

## Supported version

Latest version of Crossroad requires Swift 5.0 or above.

Use 1.x instead on Swift 4.1 or lower.

|Crossroad Version|Swift Version|Xcode Version|
|-----------------|-------------|-------------|
|2.x |5.0 |Xcode 10.2 |
|1.x |4.0 ~ 4.1 |Xcode 9.4 |

## License

Crossroad is released under the MIT License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crossroad/Extractable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension URL: Extractable {
}

public extension RawRepresentable where Self: Extractable, Self.RawValue == String {
public static func extract(from string: String) -> Self? {
static func extract(from string: String) -> Self? {
return Self(rawValue: string)
}
}
6 changes: 3 additions & 3 deletions Sources/Crossroad/OpenURLOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import UIKit

public typealias ApplicationOpenURLOptions = [UIApplicationOpenURLOptionsKey: Any]
public typealias ApplicationOpenURLOptions = [UIApplication.OpenURLOptionsKey: Any]

// https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey
public struct OpenURLOption {
Expand All @@ -21,11 +21,11 @@ public struct OpenURLOption {
public typealias DefaultRouter = Router<OpenURLOption>

public extension Router where UserInfo == OpenURLOption {
public func openIfPossible(_ url: URL, options: ApplicationOpenURLOptions) -> Bool {
func openIfPossible(_ url: URL, options: ApplicationOpenURLOptions) -> Bool {
return openIfPossible(url, userInfo: OpenURLOption(options: options))
}

public func responds(to url: URL, options: ApplicationOpenURLOptions) -> Bool {
func responds(to url: URL, options: ApplicationOpenURLOptions) -> Bool {
return responds(to: url, userInfo: OpenURLOption(options: options))
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Crossroad/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public final class Router<UserInfo> {

public extension Router where UserInfo == Void {
@discardableResult
public func openIfPossible(_ url: URL) -> Bool {
func openIfPossible(_ url: URL) -> Bool {
return openIfPossible(url, userInfo: ())
}

public func responds(to url: URL) -> Bool {
func responds(to url: URL) -> Bool {
return responds(to: url, userInfo: ())
}
}
2 changes: 1 addition & 1 deletion Tests/CrossroadTests/OpenURLOptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Crossroad

final class OpenURLOptionTests: XCTestCase {
func testInit() {
let options: [UIApplicationOpenURLOptionsKey: Any] = [
let options: [UIApplication.OpenURLOptionsKey: Any] = [
.sourceApplication: "org.giginet.myapp",
.openInPlace: true,
]
Expand Down
4 changes: 2 additions & 2 deletions Tests/CrossroadTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final class RouterTest: XCTestCase {
let value: Int
}
let router = Router<UserInfo>(scheme: scheme)
var userInfo: UserInfo? = nil
var userInfo: UserInfo?
router.register([
("foobar://static", { context in
XCTAssertEqual(context.url, URL(string: "foobar://static")!)
Expand All @@ -261,7 +261,7 @@ final class RouterTest: XCTestCase {
let value: Int
}
let router = Router<UserInfo>(scheme: scheme)
var userInfo: UserInfo? = nil
var userInfo: UserInfo?
router.register([
("static", { context in
XCTAssertEqual(context.url, URL(string: "foobar://static")!)
Expand Down

0 comments on commit 9ece0a4

Please sign in to comment.