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

611
Views
¿Es posible crear propiedades computadas genéricas con Self o requisitos de tipo asociados en Swift? De ser así, ¿cómo?

Considera lo siguiente:

 protocol SomeProtocol: Equatable {} // then, elsewhere... var someValue: Any? func setSomething<T>(_ value: T) where T: SomeProtocol { someValue = value } func getSomething<T>() -> T? where T: SomeProtocol { return someValue as? T }

Estas funciones funcionan bien, pero esencialmente actúan como propiedades calculadas. ¿Hay alguna manera de implementar algo como lo siguiente?

 var something<T>: T where T: SomeProtocol { get { return someValue as? T } set { someValue = newValue } }

Gracias por leer. Disculpas si esta pregunta ya se ha hecho en otro lugar, he buscado pero a veces mi búsqueda es débil.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe definir la propiedad computada en un tipo genérico, la propiedad computada en sí misma no puede definir un parámetro de tipo genérico.

 struct Some<T:SomeProtocol> { var someValue:Any var something:T? { get { return someValue as? T } set { someValue = newValue } } }
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!