FLKAutoLayout
FLKAutoLayout copied to clipboard
It may cause crash when using `FLKNoConstraint`
Here is what I am using:
button.alignTop("20", leading: FLKNoConstraint, bottom: FLKNoConstraint, trailing: "-27", toView: self.view)
In previous version, it works perfectly, but in 1.0 version, it cause crash.
I try to fix it with this code:
#pragma mark Generic constraint methods for two views
- (NSLayoutConstraint *)alignAttribute:(NSLayoutAttribute)attribute toView:(id)view predicate:(NSString *)predicate
{
NSArray *views = view ? @[view] : nil;
NSLayoutConstraint *constraint = [UIView alignAttribute:attribute ofViews:@[self] toViews:views predicate:predicate].firstObject;
return constraint ? constraint : [NSNull null];
}
- (NSLayoutConstraint *)alignAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(id)view predicate:(NSString *)predicate
{
NSArray *views = view ? @[view] : nil;
NSLayoutConstraint *constraint = [UIView alignAttribute:attribute ofViews:@[self] toAttribute:toAttribute ofViews:views predicate:predicate].firstObject;
return constraint ? constraint : [NSNull null];
}
Interesting, I didn't know FLKNoConstraint
existed, and I removed all nullability checks from 1.0.
I'd rather have consistent nonnull
responses, so I'll remove it entirely.
So I cannot use button.alignTop("20", leading: FLKNoConstraint, bottom: FLKNoConstraint, trailing: "-27", toView: self.view)
in the future, and should I split these FLKNoConstraint
to separate part like alignTopEdgeWithView
and alignTrailingEdgeWithView
?
Yep 👍