Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap breaks target-action on UITextField #2

Closed
dcramps opened this issue Sep 18, 2023 · 3 comments
Closed

Heap breaks target-action on UITextField #2

dcramps opened this issue Sep 18, 2023 · 3 comments

Comments

@dcramps
Copy link

dcramps commented Sep 18, 2023

Using HeapIOSAutoCapture 0.3.0 and HeapSwiftCore 0.4.0 breaks target-action usage on UITextField. When the textfield resigns first responder, something in Heap's Swizzling is sending removeTarget(self, action:"_heapControlValueChanged:event:", for: .allEvents) which is causing this issue.

Example

final class TextField: UITextField {
    public convenience init() {
        self.init(frame: .zero)
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)
        addTarget(self, action: #selector(_didChangeText), for: .editingChanged)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    @objc private func _didChangeText() {
        print("\(#function): \(text ?? "")")
    }
}

Once this TextField instance resigns first responder, _didChangeText() is never called again in subsequent editing events. This issue only appears when Heap is enabled.

Sample GIF - the text field is configured to update the label below the resign button with its text on each .editingChanged event:
Simulator Screen Recording - iPhone 15 Pro - 2023-09-18 at 14 28 10

Sample project demonstrating the issue: HeapTest.zip

Observed on iOS 16.4 and iOS 17, built with Xcode 14.3.1 and Xcode 15 RC1

@jerryhjones
Copy link

Thanks for opening this, and double thanks for including a sample project! I shared with the team, and we're going to take a look at this.

@bnickel
Copy link
Collaborator

bnickel commented Sep 19, 2023

Thanks for raising this. We are currently working on a 0.4.0 release and will incorporate at fix.

A reread of the documentation shows that the action parameter does next-to-nothing on removeTarget(_:action:for:) and there's not really a safe way to call it for an object that someone else might be using as a target. (I am assuming this was an implementation bug introduced in the first version of iOS.)

This bug should be mostly confined to custom controls since they're the only ones that would be using the control as a target.

@bnickel
Copy link
Collaborator

bnickel commented Oct 18, 2023

The fix for this is now available in version 0.4.0. Thanks again for your detailed report.

@bnickel bnickel closed this as completed Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants