Skip to content

Commit f8e30c9

Browse files
author
wxlpp
committed
WIP: demo工程修改
1 parent 3d3a881 commit f8e30c9

File tree

8 files changed

+174
-10
lines changed

8 files changed

+174
-10
lines changed

Example/Submodule/Source/SubViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class SubViewController: UIViewController {
2020
}
2121
}
2222

23-
// MARK: - 路由
23+
// MARK: 路由
2424

2525
extension SubViewController: Routable {
2626
public static func route(parameters: RouterParameters, completion: @escaping RouteCompletionHandler<SubViewController>) {

Example/Submodule/UserProfileViewController.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,23 @@
55
// Created by wxlpp on 2021/5/1.
66
//
77

8-
import Foundation
8+
import UIKit
9+
import UIRouter
10+
11+
public final class UserProfileViewController: UIViewController {}
12+
13+
// MARK: 路由
14+
15+
extension UserProfileViewController: Routable {
16+
public static func route(parameters: RouterParameters, completion: @escaping RouteCompletionHandler<UserProfileViewController>) {
17+
if let userID: String = parameters.get("userID") {
18+
completion(.success(UserProfileViewController()))
19+
} else {
20+
completion(.failure(RouteError.parameterValidationFailed(url: path, name: "userID")))
21+
}
22+
}
23+
24+
public static var path: String {
25+
"user/profile/:id"
26+
}
27+
}

Example/shell.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
AFF8753F263D28E200234826 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AFF8753E263D28E200234826 /* Assets.xcassets */; };
1414
AFF87545263D28E200234826 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AFF87543263D28E200234826 /* LaunchScreen.storyboard */; };
1515
AFF87588263D347E00234826 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFF87587263D347E00234826 /* MainViewController.swift */; };
16+
AFF875AE263D8DB800234826 /* RouteErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFF875AD263D8DB800234826 /* RouteErrorHandler.swift */; };
17+
AFF875B0263D8F8F00234826 /* ErrorDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFF875AF263D8F8F00234826 /* ErrorDetailsViewController.swift */; };
1618
/* End PBXBuildFile section */
1719

1820
/* Begin PBXFileReference section */
@@ -31,6 +33,8 @@
3133
AFF87544263D28E200234826 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
3234
AFF87546263D28E200234826 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3335
AFF87587263D347E00234826 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
36+
AFF875AD263D8DB800234826 /* RouteErrorHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteErrorHandler.swift; sourceTree = "<group>"; };
37+
AFF875AF263D8F8F00234826 /* ErrorDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorDetailsViewController.swift; sourceTree = "<group>"; };
3438
BB9D777DD817E965C11A14D5 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
3539
D66A438FC3433314207D9649 /* Pods-Example-ExampleUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example-ExampleUITests.debug.xcconfig"; path = "Target Support Files/Pods-Example-ExampleUITests/Pods-Example-ExampleUITests.debug.xcconfig"; sourceTree = "<group>"; };
3640
ED4D7EAC3A8505C19CD19DA3 /* Pods-Example-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example-ExampleUITests.release.xcconfig"; path = "Target Support Files/Pods-Example-ExampleUITests/Pods-Example-ExampleUITests.release.xcconfig"; sourceTree = "<group>"; };
@@ -100,6 +104,8 @@
100104
AFF87543263D28E200234826 /* LaunchScreen.storyboard */,
101105
AFF87546263D28E200234826 /* Info.plist */,
102106
AFF87587263D347E00234826 /* MainViewController.swift */,
107+
AFF875AD263D8DB800234826 /* RouteErrorHandler.swift */,
108+
AFF875AF263D8F8F00234826 /* ErrorDetailsViewController.swift */,
103109
);
104110
path = shell;
105111
sourceTree = "<group>";
@@ -219,6 +225,8 @@
219225
files = (
220226
AFF87588263D347E00234826 /* MainViewController.swift in Sources */,
221227
AFF87539263D28E000234826 /* AppDelegate.swift in Sources */,
228+
AFF875B0263D8F8F00234826 /* ErrorDetailsViewController.swift in Sources */,
229+
AFF875AE263D8DB800234826 /* RouteErrorHandler.swift in Sources */,
222230
AFF8753B263D28E000234826 /* SceneDelegate.swift in Sources */,
223231
);
224232
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1250"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "AFF87534263D28E000234826"
18+
BuildableName = "shell.app"
19+
BlueprintName = "shell"
20+
ReferencedContainer = "container:shell.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "AFF87534263D28E000234826"
48+
BuildableName = "shell.app"
49+
BlueprintName = "shell"
50+
ReferencedContainer = "container:shell.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "AFF87534263D28E000234826"
65+
BuildableName = "shell.app"
66+
BlueprintName = "shell"
67+
ReferencedContainer = "container:shell.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Example/shell/AppDelegate.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1515
application.router.isNeedAutoRegister = true
1616
application.router.register(interceptors: [WebInterceptor()])
17+
application.router.registerErrorHandler(RouteErrorHandler())
1718
return true
1819
}
1920

2021
// MARK: UISceneSession Lifecycle
2122

2223
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
23-
// Called when a new scene session is being created.
24-
// Use this method to select a configuration to create the new scene with.
2524
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
2625
}
2726
}

Example/shell/ErrorDetailsViewController.swift

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,63 @@
55
// Created by wxlpp on 2021/5/1.
66
//
77

8-
import Foundation
8+
import UIKit
9+
10+
class ErrorDetailsViewController: UITableViewController {
11+
let error: Error
12+
let errorDetails: [(key: String,value: String)]
13+
14+
init(error: Error) {
15+
self.error = error
16+
if let localizedError = error as? LocalizedError {
17+
var list: [(key: String,value: String)] = []
18+
if let errorDescription = localizedError.errorDescription {
19+
list.append(("简述",errorDescription))
20+
}
21+
if let failureReason = localizedError.failureReason {
22+
list.append(("原因",failureReason))
23+
24+
}
25+
if let helpAnchor = localizedError.helpAnchor {
26+
list.append(("解决",helpAnchor))
27+
28+
}
29+
if let recoverySuggestion = localizedError.recoverySuggestion {
30+
list.append(("恢复",recoverySuggestion))
31+
32+
}
33+
errorDetails = list
34+
}else {
35+
errorDetails = [("错误",error.localizedDescription)]
36+
}
37+
super.init(style: .insetGrouped)
38+
}
39+
40+
required init?(coder: NSCoder) {
41+
fatalError("init(coder:) has not been implemented")
42+
}
43+
44+
override func viewWillAppear(_ animated: Bool) {
45+
super.viewWillAppear(animated)
46+
self.title = "错误信息"
47+
}
48+
49+
override func viewDidLoad() {
50+
super.viewDidLoad()
51+
tableView.allowsSelection = false
52+
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
53+
}
54+
55+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
56+
errorDetails.count
57+
}
58+
59+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
60+
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
61+
var contentConfiguration = UIListContentConfiguration.subtitleCell()
62+
contentConfiguration.text = errorDetails[indexPath.row].key
63+
contentConfiguration.secondaryText = errorDetails[indexPath.row].value
64+
cell.contentConfiguration = contentConfiguration
65+
return cell
66+
}
67+
}

Example/shell/MainViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import UIKit
99
import UIRouter
1010
class MainViewController: UITableViewController {
1111
let routes = [(name: "SubModule", path: "sub"),
12-
(name: "Baidu", path: "https://www.baidu.com")]
12+
(name: "Baidu", path: "https://www.baidu.com"),
13+
(name: "用户简介", path: "user/profile")]
1314

1415
override func viewDidLoad() {
1516
super.viewDidLoad()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
2-
// RouteErrorInterceptor.swift
2+
// RouteErrorHandler.swift
33
// shell
44
//
55
// Created by wxlpp on 2021/5/1.
66
//
77

88
import UIRouter
99

10-
class RouteErrorHandler: RouteErrorHandler {
11-
override func handleRouteError(_ error: RouteError) {
10+
class RouteErrorHandler: RouteErrorHandling {
11+
func handleRouteError(_ error: RouteError) {
1212
#if DEBUG
1313
let vc = ErrorDetailsViewController(error: error)
1414
UIApplication.shared.route(viewcontroller: vc).presentWithNavigationController(UINavigationController.self)
@@ -17,7 +17,7 @@ class RouteErrorHandler: RouteErrorHandler {
1717
#endif
1818
}
1919

20-
override func handleCustomError(_ error: Error) {
20+
func handleCustomError(_ error: Error) {
2121

2222
}
2323
}

0 commit comments

Comments
 (0)