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

243
Views
¿El contenedor de propiedades de Swift ya no se compila en Swift 5.4+?

El siguiente código solía funcionar para Swift 5.2 y posiblemente para Swift 5.3. (La última compilación fue en noviembre de 2020)

 @propertyWrapper class ActionBindable<Button> where Button : UIControl { var target: Any? { didSet { setTargetAction() } } weak var wrappedValue: Button! { didSet { setTargetAction() } } private let action: Selector private let event: UIControl.Event init(action: Selector, event: UIControl.Event = .touchUpInside) { self.action = action self.event = event } private func setTargetAction() { guard target != nil && wrappedValue != nil else { return } wrappedValue.addTarget(target, action: action, for: event) } }

Sin embargo, ahora recibo un error: Property type 'UIKit.UIControl?' does not match 'wrappedValue' type 'UIKit.UIControl?'

No he estado siguiendo los envoltorios de propiedades durante algún tiempo, así que me pregunto qué cambió.

Aquí está el código donde se usa el contenedor de propiedades:

 @ActionBindable(action: #selector(addAction)) var addButton: UIControl!
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El error con el que tenemos que lidiar ahora es:

Cuando wrappedValue es weak , no hay ningún mecanismo para establecer explícitamente un tipo para una variable envuelta que use el envoltorio de propiedad relevante, después de su nombre.

Su solución es:

 // ActionBindable<UIControl> @ActionBindable(action: #selector(addAction)) var addButton
 // Any subclasses: @ActionBindable<UIButton>(action: #selector(addAction)) var addButton

Sin embargo, apuesto a que tendrá otros problemas, porque la opcionalidad desenvuelta implícitamente no se propaga fuera de las envolturas de propiedad. Apuesto a que solía hacerlo, dada su definición de addButton . Probablemente necesitará una variable calculada para envolver addButton entonces, para evitar futuras comprobaciones opcionales, lo que puede negar el punto de tener un envoltorio de propiedad.

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!