Ver Fonte

Added MASConstraint private header

Nikolay Tymchenko há 11 anos atrás
pai
commit
1a577997f2

+ 3 - 0
Masonry.xcworkspace/contents.xcworkspacedata

@@ -13,6 +13,9 @@
       <FileRef
          location = "group:MASConstraint.m">
       </FileRef>
+      <FileRef
+         location = "group:MASConstraint+Private.h">
+      </FileRef>
       <FileRef
          location = "group:MASCompositeConstraint.h">
       </FileRef>

+ 1 - 0
Masonry/MASCompositeConstraint.m

@@ -7,6 +7,7 @@
 //
 
 #import "MASCompositeConstraint.h"
+#import "MASConstraint+Private.h"
 
 @interface MASCompositeConstraint () <MASConstraintDelegate>
 

+ 46 - 0
Masonry/MASConstraint+Private.h

@@ -0,0 +1,46 @@
+//
+//  MASConstraint+Private.h
+//  Masonry
+//
+//  Created by Nick Tymchenko on 29/04/14.
+//  Copyright (c) 2014 cloudling. All rights reserved.
+//
+
+#import "MASConstraint.h"
+
+@protocol MASConstraintDelegate;
+
+
+@interface MASConstraint ()
+
+/**
+ *  Whether or not to check for an existing constraint instead of adding constraint
+ */
+@property (nonatomic, assign) BOOL updateExisting;
+
+/**
+ *	Usually MASConstraintMaker but could be a parent MASConstraint
+ */
+@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
+
+/**
+ *  Based on a provided value type, is equal to calling:
+ *  NSNumber - setOffset:
+ *  NSValue with CGPoint - setPointOffset:
+ *  NSValue with CGSize - setSizeOffset:
+ *  NSValue with MASEdgeInsets - setInsets:
+ */
+- (void)setLayoutConstantWithValue:(NSValue *)value;
+
+@end
+
+
+@protocol MASConstraintDelegate <NSObject>
+
+/**
+ *	Notifies the delegate when the constraint needs to be replaced with another constraint. For example
+ *  A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
+ */
+- (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
+
+@end

+ 18 - 54
Masonry/MASConstraint.h

@@ -8,8 +8,6 @@
 
 #import "MASUtilities.h"
 
-@protocol MASConstraintDelegate;
-
 /**
  *	Enables Constraints to be created with chainable syntax
  *  Constraint can represent single NSLayoutConstraint (MASViewConstraint) 
@@ -149,16 +147,6 @@
 @property (nonatomic, copy, readonly) MASConstraint *animator;
 #endif
 
-/**
- *  Whether or not to check for an existing constraint instead of adding constraint
- */
-@property (nonatomic, assign) BOOL updateExisting;
-
-/**
- *	Usually MASConstraintMaker but could be a parent MASConstraint
- */
-@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
-
 /**
  *	Creates a NSLayoutConstraint and adds it to the appropriate view.
  */
@@ -172,45 +160,6 @@
 @end
 
 
-@interface MASConstraint (Private)
-
-/**
- *  Modifies the NSLayoutConstraint constant based on a value type,
- *  see _setLayoutConstantWithValue: for details
- */
-- (MASConstraint * (^)(id))_valueOffset;
-
-/**
- *  Based on a provided value type, is equal to calling:
- *  NSNumber - setOffset:
- *  NSValue with CGPoint - setPointOffset:
- *  NSValue with CGSize - setSizeOffset:
- *  NSValue with MASEdgeInsets - setInsets:
- */
-- (void)_setLayoutConstantWithValue:(NSValue *)value;
-
-/**
- *	Sets the constraint relation to given NSLayoutRelation
- *  returns a block which accepts one of the following:
- *    MASViewAttribute, UIView, NSValue, NSArray
- *  see readme for more details.
- */
-- (MASConstraint * (^)(id attr, NSLayoutRelation relation))_equalToWithRelation;
-
-@end
-
-
-@protocol MASConstraintDelegate <NSObject>
-
-/**
- *	Notifies the delegate when the constraint needs to be replaced with another constraint. For example 
- *  A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
- */
-- (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
-
-@end
-
-
 /**
  *  Convenience auto-boxing macros for MASConstraint methods.
  *
@@ -235,12 +184,27 @@
 #endif
 
 
-@interface MASConstraint (AutocompletionSupport)
+@interface MASConstraint (AutoboxingSupport)
+
+/**
+ *  Modifies the NSLayoutConstraint constant based on a value type
+ */
+- (MASConstraint * (^)(id))_valueOffset;
+
+/**
+ *	Sets the constraint relation to given NSLayoutRelation
+ *  returns a block which accepts one of the following:
+ *    MASViewAttribute, UIView, NSValue, NSArray
+ *  see readme for more details.
+ */
+- (MASConstraint * (^)(id attr, NSLayoutRelation relation))_equalToWithRelation;
 
+/**
+ *  Dummy methods to aid autocompletion
+ */
 - (MASConstraint * (^)(id attr))mas_equalTo;
 - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
 - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
 - (MASConstraint * (^)(id offset))mas_offset;
 
-@end
-
+@end

+ 3 - 2
Masonry/MASConstraint.m

@@ -6,6 +6,7 @@
 //
 
 #import "MASConstraint.h"
+#import "MASConstraint+Private.h"
 
 #define methodNotImplemented() \
     @throw [NSException exceptionWithName:NSInternalInconsistencyException \
@@ -97,14 +98,14 @@
 - (MASConstraint * (^)(id))_valueOffset {
     return ^id(id offset) {
         NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
-        [self _setLayoutConstantWithValue:offset];
+        [self setLayoutConstantWithValue:offset];
         return self;
     };
 }
 
 #pragma mark - NSLayoutConstraint constant setter
 
-- (void)_setLayoutConstantWithValue:(NSValue *)value {
+- (void)setLayoutConstantWithValue:(NSValue *)value {
     if ([value isKindOfClass:NSNumber.class]) {
         self.offset = [(NSNumber *)value doubleValue];
     } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {

+ 1 - 0
Masonry/MASConstraintMaker.m

@@ -9,6 +9,7 @@
 #import "MASConstraintMaker.h"
 #import "MASViewConstraint.h"
 #import "MASCompositeConstraint.h"
+#import "MASConstraint+Private.h"
 #import "MASViewAttribute.h"
 #import "View+MASAdditions.h"
 

+ 2 - 1
Masonry/MASViewConstraint.m

@@ -7,6 +7,7 @@
 //
 
 #import "MASViewConstraint.h"
+#import "MASConstraint+Private.h"
 #import "MASCompositeConstraint.h"
 #import "MASLayoutConstraint.h"
 #import "View+MASAdditions.h"
@@ -78,7 +79,7 @@
 
 - (void)setSecondViewAttribute:(id)secondViewAttribute {
     if ([secondViewAttribute isKindOfClass:NSValue.class]) {
-        [self _setLayoutConstantWithValue:secondViewAttribute];
+        [self setLayoutConstantWithValue:secondViewAttribute];
     } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
         _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
     } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {

+ 1 - 1
Tests/Specs/MASConstraintDelegateMock.h

@@ -6,7 +6,7 @@
 //  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
 //
 
-#import "MASConstraint.h"
+#import "MASConstraint+Private.h"
 
 @interface MASConstraintDelegateMock : NSObject <MASConstraintDelegate>
 

+ 1 - 0
Tests/Specs/MASConstraintMakerSpec.m

@@ -9,6 +9,7 @@
 #import "MASConstraintMaker.h"
 #import "MASCompositeConstraint.h"
 #import "MASViewConstraint.h"
+#import "MASConstraint+Private.h"
 
 @interface MASConstraintMaker () <MASConstraintDelegate>
 

+ 1 - 0
Tests/Specs/MASViewConstraintSpec.m

@@ -7,6 +7,7 @@
 //
 
 #import "MASViewConstraint.h"
+#import "MASConstraint+Private.h"
 #import "MASConstraint.h"
 #import "View+MASAdditions.h"
 #import "MASConstraintDelegateMock.h"