URLNavigator
URLNavigator copied to clipboard
xcode15+ios17beta cannot adapt with https or http pattern
When I run my project with Xcode15 beta-4 and iOS17 beta-3, something is wrong with the URLNavigator.
cannot work expected;
when the value of candidate is "https://" or "http://", candidate.urlValue is nil.
waiting for release Xcode15 and iOS17
I met the same bug(or a feature?) when using Xcode 15 Beta 6 + iOS 17.0 Simulator(Beta 6).
Meanwhile, Xcode 14.3.1 + iOS 17.0 Simulator(Beta 6) works.
@Jinya yeah, the same encounter!
It‘s seems apple's issue. Apple fixed a series of beta issues including the ones I encountered. The official version is expected to resolve this issue.
Be patient and wait.
+1, it's not fixed in iOS 17 beta 8
Is this change causing this problem? @devAlanHey @devxoul
https://developer.apple.com/documentation/foundation/nsurl/1572047-urlwithstring
+1, it's not fixed in release Xcode15 and iOS17
I met the same bug(or a feature?) when using Xcode 15.0 + iOS 17.1 Simulator
Meanwhile, Xcode 15.0 + iOS 17.1 Simulator works.
只要稍微修改下匹配规则即可,将<>匹配修改为[]匹配,例如:
路由注册的代码
navigator.register("https://[path:_]") { url, _, _ -> UIViewController? in .... return vc }
URLNavigator 库中的 URLPathComponent.swift 中
extension URLPathComponent { init(_ value: String) { /* Xcode15 和 iOS 17 修改了URL的有效性校验规范,导致这种情况下无法有效初始化 URL,修改为 [path:_] 这种即可解决该问题
苹果:https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes
Github:https://github.com/devxoul/URLNavigator/issues/166
*/
//if value.hasPrefix("<") && value.hasSuffix(">") {
if value.hasPrefix("[") && value.hasSuffix("]") {
let start = value.index(after: value.startIndex)
let end = value.index(before: value.endIndex)
let placeholder = value[start..<end] // e.g. "<int:id>" -> "int:id"
let typeAndKey = placeholder.components(separatedBy: ":")
if typeAndKey.count == 1 { // any-type placeholder
self = .placeholder(type: nil, key: typeAndKey[0])
} else if typeAndKey.count == 2 {
self = .placeholder(type: typeAndKey[0], key: typeAndKey[1])
} else {
self = .plain(value)
}
} else {
self = .plain(value)
}
} }