I'm trying to add another SiriKit
intent to my Widget to allow user to select a reddit category such as top, hot, new etc. I've set my enum in my custom intents. My question is how do I get the display name from the index? It's being assigned to a URL string so the rawValue
won't work. I attempted to use Sort(rawValue:configuration.sort.rawValue)!
with the same results https://www.reddit.com/r/swiftui/1.json
. I need the url to behttps://www.reddit.com/r/swiftui/hot.json
.
I ended up creating an Int enum
containing the same as in my intentdefinition
. Then created an extension
for my enum
to return a string value for the intent's rawValue
. I was mistaken that my intentdefinition
would provide me a string value for the index.
enum SortBy : Int {
case hot = 1
case new
case controversial
case top
case rising
}
extension SortBy {
var sortValue: String {
switch self {
case .hot:
return "hot"
case .new:
return "new"
case .controversial:
return "controversial"
case .top:
return "top"
case .rising:
return "rising"
}
}
}
SortBy(rawValue: configuration.sort.rawValue)!