oleksii-demedetskyi / Parus

Parus is simple chain style auto-layout helper for objective-c.
MIT License
106 stars 4 forks source link

Can't test VFL constraints #14

Closed Forsarion closed 10 years ago

Forsarion commented 10 years ago

Trying to test this one VFL:

        view1 = [UIView new];
        UIView* container = [UIView new];
        [container addSubview:view1];

        NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-50-[view1]-50-|"
                                                                       options:0
                                                                       metrics:nil
                                                                         views:NSDictionaryOfVariableBindings(view1)];

Getting compile error: NSInvalidArgumentException: Unable to parse constraint format:

Still don't know why this happens.

xNekOIx commented 10 years ago

View doesn't added to view hierarchy. Therefore it can't specify superview in single constraint.

NSInvalidArgumentException: Unable to parse constraint format: 
Unable to interpret '|' character, because the related view doesn't have a superview 
|-50-[view1]-50-| 

e.g.

[NSLayoutConstraint constraintWithItem:superview
                                 attribute:NSLayoutAttributeLeft
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:view1
                                 attribute:NSLayoutAttributeLeft
                                multiplier:1.f
                                  constant:50.f];
Forsarion commented 10 years ago

Sorry, haven't posted all code, view is actually added to superview.

xNekOIx commented 10 years ago

The following code doesn't raise any exceptions

UIView* view3 = [UIView new];
UIView* container = [UIView new];
[container addSubview:view3];

NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-50-[view3]-50-|"
                                                                           options:0
                                                                           metrics:nil
                                                                             views:NSDictionaryOfVariableBindings(view3)];
Forsarion commented 10 years ago

I don't see a scope of the following code. In the UI application it works fine without any exceptions. But when I'm trying to compile it during test it fails - that is actually the problem.

Forsarion commented 10 years ago

Views and superviews that are used for constraints should be block variables - they will not be realesed after "before" block fired.