-
Notifications
You must be signed in to change notification settings - Fork 197
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
Can't use TextAlignmentConstraint within Interface Builder #355
Comments
Thanks for reporting this. On first reading, I believe this should be working. I’ll dig into it soon and get back to you. I don’t use Interface builder, so I wouldn’t be surprised if this had regressed. If I can fix it, I’ll add tests 😉 |
Hey Matt, Thanks again for your detailed bug report! I was able to reproduce your issue. I don't yet know what is causing it, but I have a little more info and two workaround for you. Workaround 1
Workaround 2Use CocoaPods. Unpopular opinion, perhaps, but I tested it and I was able to use the constraint as intended without any issues. Unanswered QuestionsI created a framework target inside my example project, and added a Swift file to it that looked like this: import UIKit
@objc(PREFIXEDMyConstraint)
public class MyConstraint: NSLayoutConstraint {
@IBInspectable var coolBeans: String?
public override func awakeFromNib() {
super.awakeFromNib()
print("coolBeans:", String(describing: coolBeans))
}
} With that in place, I was able to refer to the class in Interface Builder as It looks like, at the very least, we should update the docs to make this more clear, but I'd love to find and fix the underlying issue. |
Here's a project that reproduces the issue. If you convert it over to using CocoaPods, you can use the constraint in IB without issue. |
Yeah, it’s an Xcode limitation: anything pre-compiled (by Carthage or otherwise) doesn’t get the extra attributes in the attributes inspector. You can remove the Carthage-compiled framework, use a workspace, and add and integrate (to that workspace) There’s another workaround involving editing BonMot source code, but honestly not really worth it…That method — modifying
Honestly, not sure either this or the method from the video are worth the hassle. Just using the user-defined runtime attributes is ergonomic enough. |
Issue
I'm unable to use the
TextAlignmentConstraint
within Interface Builder.Changing the custom constraint class to
TextAlignmentConstraint
has no effect and the attribute extra attributes do not appear in the attributes inspector. At runtime, this appears in the console:This is a Swift project and I am trying to include the constraint within a
UITableViewCell
xib.My Environment
I am using BonMot 5.3 via Carthage.
Things I've Tried
I can create the constraint in code no problem.
If I specify
BONTextAlignmentConstraint
for the custom class name in Interface Builder, it works but the extra attributes don't appear and it crashes at runtime on line 188 ofTextAlignmentConstraint.swift
:With:
My suspicion is that Interface Builder can't find constraints within imported frameworks? If I create a custom constraint within my own project, it is able to find that. I tried this:
But TextAlignmentConstraint is not open.
The text was updated successfully, but these errors were encountered: