Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
Swift: 'Hashable.hashValue' está en desuso como requisito de protocolo;

Me he enfrentado al siguiente problema (es solo una advertencia) con mi proyecto de iOS.

'Hashable.hashValue' está en desuso como requisito de protocolo; ajuste el tipo 'ActiveType' a 'Hashable' implementando 'hash(into:)' en su lugar

  • Xcode 10.2
  • rápido 5

Código fuente:

 public enum ActiveType { case mention case hashtag case url case custom(pattern: String) var pattern: String { switch self { case .mention: return RegexParser.mentionPattern case .hashtag: return RegexParser.hashtagPattern case .url: return RegexParser.urlPattern case .custom(let regex): return regex } } } extension ActiveType: Hashable, Equatable { public var hashValue: Int { switch self { case .mention: return -1 case .hashtag: return -2 case .url: return -3 case .custom(let regex): return regex.hashValue } } }

ingrese la descripción de la imagen aquí

¿Alguna solución mejor? La advertencia en sí me sugiere que implemente 'hash (en:)' pero no sé, ¿cómo?

Referencia: ActiveLabel

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Como dice la advertencia, ahora debería implementar la hash(into:) su lugar.

 func hash(into hasher: inout Hasher) { switch self { case .mention: hasher.combine(-1) case .hashtag: hasher.combine(-2) case .url: hasher.combine(-3) case .custom(let regex): hasher.combine(regex) // assuming regex is a string, that already conforms to hashable } }

Sería incluso mejor (en el caso de enumeraciones y estructuras) eliminar la implementación de hash(into:) (a menos que necesite una implementación específica), ya que el compilador la sintetizará automáticamente.

Simplemente haga que su enumeración se ajuste a ella:

 public enum ActiveType: Hashable { case mention case hashtag case url case custom(pattern: String) var pattern: String { switch self { case .mention: return RegexParser.mentionPattern case .hashtag: return RegexParser.hashtagPattern case .url: return RegexParser.urlPattern case .custom(let regex): return regex } } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!