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

BonMot disables IBActions dragging from storyboard #252

Closed
leojkwan opened this issue Nov 26, 2016 · 19 comments
Closed

BonMot disables IBActions dragging from storyboard #252

leojkwan opened this issue Nov 26, 2016 · 19 comments

Comments

@leojkwan
Copy link

When Bonmot is included in my project, all my UIButton 'Touch Up Inside' events in the connections inspector via Utilities show warning signs. I suspect it has something with this stack overflow issue: http://stackoverflow.com/questions/28732903/cant-connect-ibaction-in-xcode.

screen shot 2016-11-26 at 12 21 13 pm

As one of the commenters suggested in the link, the culprit seems to be the UIButton extensions in BonMot's framework.

I commented the several extensions for UIButton out and now it works fine.

Going to work with clone bonmot into own project in meantime, but would love for this to be addressed!

@ZevEisenberg
Copy link
Collaborator

@leojkwan thanks for reporting this. I was able to reproduce your issue, but I can't figure out what to comment out in order to get buttons to be able to send events again. What did you comment to get it to work?

@leojkwan
Copy link
Author

leojkwan commented Dec 1, 2016

Hi @ZevEisenberg, Just comment out all extensions of UIButton in Bon Mot framework, theres at least three places that have them.

@leojkwan
Copy link
Author

leojkwan commented Dec 1, 2016

//extension UIButton: StyleableUIElement {
//
//    /// The name of a style in the global `NamedStyles` registry. The getter
//    /// always returns `nil`, and should not be used.
//    @IBInspectable
//    public var bonMotStyleName: String? {
//        get { return nil }
//        set {
//            guard let font = titleLabel?.font else { fatalError("Unable to get the font. This is unexpected; see UIKitTests.testTextFieldPropertyBehavior") }
//            bonMotStyle = lookUpSharedStyle(for: newValue, font: font)
//        }
//    }
//
//    /// A string style. Stored via associated objects.
//    public final var bonMotStyle: StringStyle? {
//        get { return getAssociatedStyle() }
//        set {
//            setAssociatedStyle(bonMotStyle: newValue)
//            styledText = titleLabel?.text
//        }
//    }
//
//    /// Update this property to style the incoming text via the `bonMotStyle`
//    /// and set it as the receiver's attributed text for the "normal" state.
//    @objc(bon_styledText)
//    public var styledText: String? {
//        get { return titleLabel?.text }
//        set {
//            let styledText = styledAttributedString(from: newValue)
//            setAttributedTitle(styledText, for: .normal)
//        }
//    }
//
//}

//        extension UIButton {
//
//            @nonobjc final func setAttributedTitle(title: NSAttributedString?, for state: UIControlState) {
//                setAttributedTitle(title, forState: state)
//            }
//
//        }

//extension UIButton: AdaptableTextContainer {
//
//    /// Adapt `attributedTitle`, for all control states, to the specified trait collection.
//    ///
//    /// - parameter traitCollection: The new trait collection.
//    @objc(bon_updateTextForTraitCollection:)
//    public func adaptText(forTraitCollection traitCollection: UITraitCollection) {
//        for state in UIControlState.commonStates {
//            #if swift(>=3.0)
//                let attributedText = attributedTitle(for: state)?.adapted(to: traitCollection)
//                setAttributedTitle(attributedText, for: state)
//            #else
//                let attributedText = attributedTitleForState(state)?.adapted(to: traitCollection)
//                setAttributedTitle(attributedText, forState: state)
//            #endif
//        }
//    }
//
//}

@mtorcutt
Copy link

mtorcutt commented Dec 8, 2016

I am experiencing the same issue in xCode 8.2.

@ZevEisenberg ZevEisenberg mentioned this issue Dec 8, 2016
1 task
@ZevEisenberg
Copy link
Collaborator

Has anyone been able to find a fix, other than just commenting out the offending code? We don't use IB much at Raizlabs, which is why we didn't catch this.

@leojkwan
Copy link
Author

@ZevEisenberg Agreed. Instead of commenting out the protocol extensions for UIButton, we can subclass UIButton and provide the protocol extensions to the subclass. The subclass will just be an empty declaration, and any existing buttons referencing the UIButton extension methods on BonMot will have to subclass this interface. I don't know why this bug is happening, but I think it's worth the quick fix as I suspect there are a ton of projects using BonMot with at least 1 @IBAction from a UIButton from Storyboard.

class BonMotButton: UIButton {
  
}

extension BonMotButton {

    @nonobjc final func setAttributedTitle(title: NSAttributedString?, for state: UIControlState) {
         setAttributedTitle(title, forState: state)
    }
}

@jhoughjr
Copy link

I've fixed this in situ in my own project by unlocking the pod.
I just cloned the repo and created a branch for the fix ,
but what worked in my project isn't working the same in BonMot.

@jhoughjr
Copy link

I think I have it fixed, but i cloned instead of forking. Pull request incoming within the hour!

@ZevEisenberg
Copy link
Collaborator

I was also wondering whether doing the extension in Objective-C might work, but I haven't explored it much. I'd prefer to avoid subclassing if possible.

@jhoughjr
Copy link

The subclassing solution is almost working in my fork, just working on getting the tests passing.
I think there is value in a pure swift implementation.

@ZevEisenberg
Copy link
Collaborator

I would prioritize pragmatism (Objective-C) over purity (pure Swift). This project is so tightly bound to UIKit/AppKit that there's not much benefit in avoiding Objective-C, since you're not going to be able to use it on Linux without NSAttributedString and its platform-specific dependencies anyway.

@delewis2015
Copy link

Hello, we just ran into this on our new project. Right now we are commenting this out, because we dont really use it at the moment, but I was wandering if a fix is actively being pursued at the moment. I see there was some progress recently, but that its still not assigned. What I can offer is that this issue affects all the controls, not just the button. Adding any protocol to an extension of the apple provided base class causes this: https://forums.developer.apple.com/thread/25180

@sachithamh
Copy link

yep same problem in xcode 8.2.1 👎 please give a solution

@benyboariu
Copy link

We really need a fix for this. BonMot is such a beauty, but right now all IBActions are disabled :(
Please fix it. Already reported on SO as a problem.
http://stackoverflow.com/questions/28732903/cant-connect-ibaction-in-xcode/41546732#41546732

@ZevEisenberg
Copy link
Collaborator

Sorry for the continued inconvenience, everyone! I've been on vacation for the last few days. I'm going to put some time into this and see what I can dig up, or try to track down someone at Apple who knows what's up. Thanks for your continued patience. As a workaround, you can assign actions in code. It stinks, but it should keep your code shippable until we get this solved :(

@ZevEisenberg
Copy link
Collaborator

There were some radars filed on that Apple thread, but I filed my own so I can keep this thread updated if I hear any updates: http://openradar.me/30001713

Still working on a fix or workaround.

@ZevEisenberg
Copy link
Collaborator

Sorry again for the delay. If you've been seeing this problem, please try the fix from #259 and let us know if it works for you. We should be able to get it merged pretty soon.

@ZevEisenberg
Copy link
Collaborator

This is now fixed in 4.0.2. Try it out and let us know if you find any problems!

@benyboariu
Copy link

Awesome, it's fixed now in 4.0.2. Thank you very much sir, and again, really awesome lib :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants