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

It may cause crash when using FLKNoConstraint #49

Open
gonghao opened this issue May 18, 2016 · 4 comments
Open

It may cause crash when using FLKNoConstraint #49

gonghao opened this issue May 18, 2016 · 4 comments

Comments

@gonghao
Copy link

gonghao commented May 18, 2016

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.

@gonghao
Copy link
Author

gonghao commented May 18, 2016

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];
}

@orta
Copy link
Collaborator

orta commented May 18, 2016

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.

@gonghao
Copy link
Author

gonghao commented May 18, 2016

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 ?

@orta
Copy link
Collaborator

orta commented May 18, 2016

Yep 👍

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

2 participants