Questions tagged [swift-hashable]

This tag should be used for questions about Swift's Hashable protocol only.

Use the tag for questions about Swift's Hashable protocol only.

For more information, see the Hashable documentation.

For questions about the Hashable package, use the tag instead.

6 questions
2
votes
1 answer

How can I make CMTime conform to Hashable on all iOS versions?

On Xcode 14, Apple added Hashable conformance to CMTime and CMTimeRange to iOS16 only. I'm trying to make it Hashable for all iOS versions, because we have many Hashable structs that contain CMTime, and they depend on CMTime to be Hashable as…
Guy Niv
  • 23
  • 2
2
votes
2 answers

Swift enum conformance to identifiable: Type doesn't conform to Identifiable protocol

I have an enum with associated values, which I want to use as an item in RxDataSources. I tried conforming it to identifiable by conforming it to Hashable like below enum DriverHubWidget: Hashable, Identifiable { static func == (lhs:…
1
vote
2 answers

NavigationStack pushing too many views

Hello I am fairly new to swiftui and I am creating a NavigationStack from an array of items. Every item in the array is pushed into navigation when I click on the item (I have to click the back button many times to get back to the root) I can't seem…
0
votes
1 answer

Swift - Making a struct hashable that has a property of protocol type

I have a struct that needs to be Decodable and Hashable. This struct has a property that is of a Protocol type. Depending on the type a concrete value of the protocol is filled in the struct. But how do I make this struct hashable without making the…
tarun_sharma
  • 761
  • 5
  • 22
0
votes
0 answers

How to make the class 'Sound' conform to 'Hashable' in a ForEach loop in SwiftUI

I am trying to create an audio mixing panel for about 8 audio loops, but the approach I took requires the class Sound to conform to 'Hashable'. I have looked at others who fixed something similar and tried it by simply adding :Hashable, but then it…
Florian
  • 107
  • 1
  • 8
0
votes
1 answer

When is hashValue in swift computed?

Let's say I have a massive String, so hashing it is fairly expensive. When does the hashValue gets computed? Every time I access it as words.hashValue, or every time the String gets modified? If it's on access, is it cached?
Vladislav
  • 1,392
  • 1
  • 12
  • 21