You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a URL and query parameter that I'm trying to parse into a FilterScreenTab, without the intermediate step of manually parsing out a String. I've looked across all the discussions and tried a few approaches, but none of them seem to work.
What I'm trying to do is to take this case in my app router:
/// plinky://open/filters?screen=[String]
case linksFilterScreen(screen: Screen)
And have the associated value use the FilterScreenTab type directly, like so.
/// plinky://open/filters?screen=[String]
case linksFilterScreen(tab: FilterScreenTab)
My current approach is to take the screen parameter and to convert it into a tab through an initializer.
func handleScreenDeepLink(_ screen:AppRoute.Screen){
switch screen {case.linksFilterScreen(let screen):lettab=FilterScreenTab(string: screen)self.appState.$selectedFilterTab.set(tab)
// More code here
}}privateextensionFilterScreenTab{init(string:String){lettab:FilterScreenTab= switch string {casescreenParameter(for:URL.actions.openSearchLinksScreen):.search
casescreenParameter(for:URL.actions.openTagsScreen):.tags
casescreenParameter(for:URL.actions.openFoldersScreen):.collections
default:.search
}self= tab
}func screenParameter(for url:URL)->String?{
guard let queryItems =URLComponents(string: url.absoluteString)?.queryItems else{returnnil}
for queryItem in queryItems where queryItem.name =="screen"{return queryItem.value
}returnnil}}
I came across a few solutions such as #69, but all of the approaches in there seemed to provide me different sets of errors.
While the manual conversion works, I tried tried constructing queries like so:
And none of them quite worked. The last thing I tried was to conform to Conversion and see if I could get that working, but I ran into a different set of errors.
extensionConversionwhere Input ==String, Output ==FilterScreenTab{publicfunc apply(_ input:Input)throws->Output{lettab:FilterScreenTab= switch input {casescreenParameter(for:URL.actions.openSearchLinksScreen):.search
casescreenParameter(for:URL.actions.openTagsScreen):.tags
casescreenParameter(for:URL.actions.openFoldersScreen):.collections
default:.search
}return tab
}publicfunc unapply(_ output:Output)throws->Input{
switch output {case.search:screenParameter(for:URL.actions.openSearchLinksScreen)case.tags:screenParameter(for:URL.actions.openTagsScreen)case.collections:screenParameter(for:URL.actions.openFoldersScreen)default:screenParameter(for:URL.actions.openSearchLinksScreen)}}func screenParameter(for url:URL)->String?{
guard let queryItems =URLComponents(string: url.absoluteString)?.queryItems else{returnnil}
for queryItem in queryItems where queryItem.name =="screen"{return queryItem.value
}returnnil}}
It's not a huge issue but I'd like to see if there's a way for me to build this, ideally without conforming to RawRepresentable.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a URL and query parameter that I'm trying to parse into a
FilterScreenTab
, without the intermediate step of manually parsing out a String. I've looked across all the discussions and tried a few approaches, but none of them seem to work.What I'm trying to do is to take this case in my app router:
And have the associated value use the
FilterScreenTab
type directly, like so.My current approach is to take the
screen
parameter and to convert it into atab
through an initializer.I came across a few solutions such as #69, but all of the approaches in there seemed to provide me different sets of errors.
While the manual conversion works, I tried tried constructing queries like so:
And none of them quite worked. The last thing I tried was to conform to
Conversion
and see if I could get that working, but I ran into a different set of errors.It's not a huge issue but I'd like to see if there's a way for me to build this, ideally without conforming to
RawRepresentable
.Beta Was this translation helpful? Give feedback.
All reactions