Skip to content

Commit

Permalink
Merge branch 'master' of github.com:marcoarment/CompactConstraint
Browse files Browse the repository at this point in the history
# Conflicts:
#	CompactConstraint/NSLayoutConstraint+CompactConstraint.m
  • Loading branch information
marcoarment committed Nov 28, 2017
2 parents 8f4454a + d058082 commit da56296
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CompactConstraint/NSLayoutConstraint+CompactConstraint.h
Expand Up @@ -3,6 +3,8 @@
// Copyright (c) 2014 Marco Arment. See included LICENSE file.
//

#import "TargetConditionals.h"

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
Expand Down
12 changes: 12 additions & 0 deletions CompactConstraint/NSLayoutConstraint+CompactConstraint.m
Expand Up @@ -3,6 +3,8 @@
// Copyright (c) 2014 Marco Arment. See included LICENSE file.
//

#import "TargetConditionals.h"

#if TARGET_OS_IPHONE
#define kPriorityRequired UILayoutPriorityRequired
#else
Expand Down Expand Up @@ -49,6 +51,7 @@ + (NSArray *)identifiedConstraintsWithVisualFormat:(NSString *)format options:(N
// For release builds, where the asserted variables (leftOperandScanned, etc.) aren't used because the assertions are removed
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-value"

+ (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary *)metrics views:(NSDictionary *)views self:(id)selfView
{
Expand Down Expand Up @@ -117,6 +120,7 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
NSString *identifier = relationship;

BOOL leftOperandScanned = [scanner scanUpToCharactersFromSet:leftOperandTerminatingCharacterSet intoString:&leftOperandStr];
#pragma unused(leftOperandScanned)
NSAssert(leftOperandScanned, @"No left operand given");
leftOperandStr = [leftOperandStr stringByTrimmingCharactersInSet:leftOperandTerminatingCharacterSet];
NSRange lastDot = [leftOperandStr rangeOfString:@"." options:NSBackwardsSearch];
Expand All @@ -135,6 +139,7 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
leftAttribute = (NSLayoutAttribute) [leftAttributeNumber integerValue];

BOOL operatorScanned = [scanner scanCharactersFromSet:operatorCharacterSet intoString:&operatorStr];
#pragma unused(operatorScanned)
NSAssert(operatorScanned, @"No operator given");
NSLayoutRelation relation;
if ([operatorStr isEqualToString:@"=="] || [operatorStr isEqualToString:@"="]) relation = NSLayoutRelationEqual;
Expand All @@ -150,6 +155,7 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
// right operand is a symbol. Either a metric or a view. Views have dot-properties, metrics don't.
BOOL rightOperandScanned = [scanner scanUpToCharactersFromSet:rightOperandTerminatingCharacterSet intoString:&rightOperandStr];
NSAssert(rightOperandScanned, @"No right operand given");
#pragma unused(rightOperandScanned)

lastDot = [rightOperandStr rangeOfString:@"." options:NSBackwardsSearch];
if (lastDot.location == NSNotFound) {
Expand Down Expand Up @@ -198,6 +204,8 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
// see if the scalar is a metric instead of a literal number
BOOL scalarAfterMultiplication = [scanner scanUpToCharactersFromSet:rightOperandTerminatingCharacterSet intoString:&rightValueStr];
NSAssert(scalarAfterMultiplication, @"No scalar given after '*' on right side");
#pragma unused(scalarAfterMultiplication)

rightMetricNumber = metrics[rightValueStr];
NSAssert1(rightMetricNumber, @"Right scalar '%@' not found in metrics dictionary", rightValueStr);
rightScalar = [rightMetricNumber doubleValue];
Expand All @@ -211,6 +219,8 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
// see if the scalar is a metric instead of a literal number
BOOL constantAfterAddition = [scanner scanUpToCharactersFromSet:rightOperandTerminatingCharacterSet intoString:&rightValueStr];
NSAssert(constantAfterAddition, @"No constant given after '+' on right side");
#pragma unused(constantAfterAddition)

rightMetricNumber = metrics[rightValueStr];
NSAssert1(rightMetricNumber, @"Right constant '%@' not found in metrics dictionary", rightValueStr);
rightConstant = [rightMetricNumber doubleValue];
Expand All @@ -229,6 +239,8 @@ + (instancetype)compactConstraint:(NSString *)relationship metrics:(NSDictionary
// see if the priority is a metric instead of a literal number
BOOL priorityAfterAt = [scanner scanUpToCharactersFromSet:rightOperandTerminatingCharacterSet intoString:&rightValueStr];
NSAssert(priorityAfterAt, @"No priority given after '@' on right side");
#pragma unused(priorityAfterAt)

rightMetricNumber = metrics[rightValueStr];
NSAssert1(rightMetricNumber, @"Right priority '%@' not found in metrics dictionary", rightValueStr);
priority = [rightMetricNumber doubleValue];
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -39,7 +39,7 @@ CompactConstraint syntax maps directly to the paramters passed to NSLayoutConstr

`leftItem` and `rightItem` are keys from the supplied `views` dictionary that map to UIViews, just like with Apple's visual-format-language calls.

`rightItem` may be "super", which is interpreted as `leftItem`'s superview. If you specify a `@"super"` key in `views`, your supplied value will be used instead.
`rightItem` may be "super", which is interpreted as `leftItem`'s superview, or "safe", which is interpreted as `leftItem`'s superview's `safeAreaLayoutGuide`. If you specify `@"super"` or `@"safe"` keys in `views`, your supplied values will be used instead.

`multiplier`, `constant`, `priority`, and `identifier` are optional. Additionally, `rightItem.attribute`, `multiplier`, `constant`, and `priority` can all optionally be replaced by entries in the supplied `metrics` dictionary, mapping to NSNumbers.

Expand Down

0 comments on commit da56296

Please sign in to comment.