Open mattcomi opened 5 years ago
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.
BONTextAlignmentConstraint
.@IBInspectable
properties to work, but it does work if you pass the values manually in user-defined runtime attributes. You need to add entries for string properties called firstAlignment
and secondAlignment
, and you can pass any of these as values: top
, cap height
, x-height
, first baseline
, last baseline
, bottom
.Use CocoaPods. Unpopular opinion, perhaps, but I tested it and I was able to use the constraint as intended without any issues.
I 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 PREFIXEDMyConstraint
, and set the inspectable properties without having to use user-defined runtime attributes. I don't know what the difference is with the Carthage-built framework, nor why it works in CocoaPods.
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) BonMot.xcodeproj
. That should be all that’s necessary, but (with Xcode 10.1 and Zev’s BonTest.zip) Interface Builder can’t find the class for some reason — messing about, I kept seeing the error Unknown class __TtC6BonMot23TextAlignmentConstraint in Interface Builder file.
There’s a couple workarounds, made a screencast showing one of them in effect:
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.