diff --git a/CompactConstraint/NSLayoutConstraint+CompactConstraint.h b/CompactConstraint/NSLayoutConstraint+CompactConstraint.h index c0b620e..2582cbf 100644 --- a/CompactConstraint/NSLayoutConstraint+CompactConstraint.h +++ b/CompactConstraint/NSLayoutConstraint+CompactConstraint.h @@ -3,6 +3,8 @@ // Copyright (c) 2014 Marco Arment. See included LICENSE file. // +#import "TargetConditionals.h" + #if TARGET_OS_IPHONE #import #else diff --git a/CompactConstraint/NSLayoutConstraint+CompactConstraint.m b/CompactConstraint/NSLayoutConstraint+CompactConstraint.m index b3edabb..b627023 100644 --- a/CompactConstraint/NSLayoutConstraint+CompactConstraint.m +++ b/CompactConstraint/NSLayoutConstraint+CompactConstraint.m @@ -3,6 +3,8 @@ // Copyright (c) 2014 Marco Arment. See included LICENSE file. // +#import "TargetConditionals.h" + #if TARGET_OS_IPHONE #define kPriorityRequired UILayoutPriorityRequired #else @@ -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 { @@ -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]; @@ -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; @@ -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) { @@ -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]; @@ -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]; @@ -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]; diff --git a/README.md b/README.md index 9d98a50..18fd24e 100644 --- a/README.md +++ b/README.md @@ -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.