IDE: Fire Version: Version 10.0.0.2398 (develop) built on bajor, 20190424-095707. Commit b865645. Target (If relevant): _iOS Description:
I am getting an error when I try to manage layout constraints while working with UITableViewCell. I keeping track of all the applied layout constraints (as seen in Eureka!) by defining the following: open var dynamicConstraints = [NSLayoutConstraint]().
Next I am adding a bunch of NSLayoutConstraint-instances like: dynamicConstraints += NSLayoutConstraint.constraints(visualFormat: "V:|-11-[textField]-11-|", options: .alignAllLastBaseline, metrics: nil, views: views)
If I now then try to add the constraints to a view using: contentView.addConstraints(dynamicConstraints) or remove them via contentView.removeConstraints(dynamicConstraints) I am getting the following compiler error:
E: Parameter 1 is "Swift.Array<NSLayoutConstraint!>", should be "NSArray<Dynamic<NSLayoutConstraint!>>!", in call to func UIView!.removeConstraints(_ constraints: NSArray<Dynamic<NSLayoutConstraint!>>!) [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (71)]
E: Parameter 1 is "Swift.Array<NSLayoutConstraint!>", should be "NSArray<Dynamic<NSLayoutConstraint!>>!", in call to func UIView!.addConstraints(_ constraints: NSArray<Dynamic<NSLayoutConstraint!>>!) [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (98)]
Expected Behavior:
I would expect I can directly apply the array without needing to cast it
Actual Behavior:
I need to cast the code to the following to make it compile contentView.removeConstraints(dynamicConstraints as! NSArray<Dynamic<NSLayoutConstraint!>>)
Can you do small-fish test cases for these? a huge cross-platform project with dozens of files really is hard to debug. (also, the project you sent compiles clean for me).
Only still getting this issue and I am seem to be unable to set a breakpoint before where I am appending the customConstraints-array as then the app in the simulator gets stuck and nothing happens. I am happy to show what’s going on over screen sharing.
Hmm, I think I might found the potential issue. Not 100% sure but when I instead of using the += operator actually use append I am getting the following compiler error:
E: Parameter 1 is "NSArray<Dynamic<NSLayoutConstraint!>>", should be "NSLayoutConstraint!", in call to func Swift.Array<NSLayoutConstraint!>.append(_ newElement: NSLayoutConstraint!) [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (182)]
If I change my code to dynamicConstraints = dynamicConstraints + NSLayoutConstraint.constraints(visualFormat: "H:|-[textField]-|", options: .alignAllLeft, metrics: nil, views: views) it’s working fine.
Looks like the operator overload for += is missing
Not sure why this code wouldn’t fail compiler time though