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

242
Views
Swift property wrapper not compiling any more in Swift 5.4+?

The following code used to work for Swift 5.2, and possibly Swift 5.3. (Last build was November 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)
    }
    
}

However, I'm getting an error now: Property type 'UIKit.UIControl?' does not match 'wrappedValue' type 'UIKit.UIControl?'

Haven't been following property wrappers for some time, so I'm wondering what changed.

Here is the code where the property wrapper is being used:

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

0

The bug we have to deal with right now is:

When wrappedValue is weak, there is no mechanism to explicitly set a type for a wrapped variable that uses the relevant property wrapper, after its name.

Your workaround is:

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

However, I bet you'll have other problems, because implicitly-unwrapped optionality doesn't propagate outside of property wrappers. I bet it used to, given your addButton definition. You'll probably need a computed variable to wrap addButton then, to avoid future optional checking, which may negate the point of having a property wrapper.

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!