Authored by Jonas Budelmann

move NSObject addition other classes and additions

... ... @@ -30,8 +30,6 @@
DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1DC179CAACA005CD195 /* MASCompositeConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD7CC16E17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD7CC16F17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */; };
DD7CC17217ACDC7A007A469E /* NSObject+MASKeyAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7CC17017ACDC7A007A469E /* NSObject+MASKeyAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD7CC17317ACDC7A007A469E /* NSObject+MASKeyAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC17117ACDC7A007A469E /* NSObject+MASKeyAdditions.m */; };
DD93AAF317ACB647008F7D21 /* MASLayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD93AAF117ACB647008F7D21 /* MASLayoutConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD93AAF417ACB647008F7D21 /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = DD93AAF217ACB647008F7D21 /* MASLayoutConstraint.m */; };
DDE2653F179D24E600D48565 /* UIView+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
... ... @@ -89,8 +87,6 @@
DD52F1ED179CAAEE005CD195 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = "<group>"; };
DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = "<group>"; };
DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = "<group>"; };
DD7CC17017ACDC7A007A469E /* NSObject+MASKeyAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+MASKeyAdditions.h"; sourceTree = "<group>"; };
DD7CC17117ACDC7A007A469E /* NSObject+MASKeyAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+MASKeyAdditions.m"; sourceTree = "<group>"; };
DD93AAF117ACB647008F7D21 /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = "<group>"; };
DD93AAF217ACB647008F7D21 /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = "<group>"; };
DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASShorthandAdditions.h"; sourceTree = "<group>"; };
... ... @@ -207,8 +203,6 @@
DD52F1E5179CAACA005CD195 /* UIView+MASAdditions.h */,
DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */,
DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */,
DD7CC17017ACDC7A007A469E /* NSObject+MASKeyAdditions.h */,
DD7CC17117ACDC7A007A469E /* NSObject+MASKeyAdditions.m */,
DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */,
DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */,
);
... ... @@ -249,7 +243,6 @@
DD52F269179CB34A005CD195 /* MASViewConstraint.h in Headers */,
DD93AAF317ACB647008F7D21 /* MASLayoutConstraint.h in Headers */,
DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */,
DD7CC17217ACDC7A007A469E /* NSObject+MASKeyAdditions.h in Headers */,
DD7CC16E17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
... ... @@ -390,7 +383,6 @@
DD52F1EB179CAACA005CD195 /* UIView+MASAdditions.m in Sources */,
DD93AAF417ACB647008F7D21 /* MASLayoutConstraint.m in Sources */,
DD7CC16F17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
DD7CC17317ACDC7A007A469E /* NSObject+MASKeyAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...
... ... @@ -9,10 +9,10 @@
#import "MASCompositeConstraint.h"
#import "UIView+MASAdditions.h"
#import "MASViewConstraint.h"
#import "NSObject+MASKeyAdditions.h"
@interface MASCompositeConstraint () <MASConstraintDelegate>
@property (nonatomic, strong) id mas_key;
@property (nonatomic, strong) NSMutableArray *childConstraints;
@end
... ...
... ... @@ -14,4 +14,9 @@
*/
@interface MASLayoutConstraint : NSLayoutConstraint
/**
* a key to associate with this constraint
*/
@property (nonatomic, strong) id mas_key;
@end
... ...
... ... @@ -9,7 +9,6 @@
#import "MASViewConstraint.h"
#import "MASCompositeConstraint.h"
#import "MASLayoutConstraint.h"
#import "NSObject+MASKeyAdditions.h"
@interface MASViewConstraint ()
... ... @@ -20,6 +19,7 @@
@property (nonatomic, assign) CGFloat layoutMultiplier;
@property (nonatomic, assign) CGFloat layoutConstant;
@property (nonatomic, assign) BOOL hasLayoutRelation;
@property (nonatomic, strong) id mas_key;
@end
... ...
... ... @@ -7,7 +7,6 @@
//
#import <UIKit/UIKit.h>
#import "NSObject+MASKeyAdditions.h"
/**
* makes debug and log output of NSLayoutConstraints more readable
... ... @@ -16,3 +15,20 @@
@end
/**
* Allows you to attach keys to objects matching the variable names passed.
*
* view1.mas_key = @"view1", view2.mas_key = @"view2";
*
* is equivalent to:
*
* MASAttachKeys(view1, view2);
*/
#define MASAttachKeys(...) \
NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
for (id key in keyPairs.allKeys) { \
id obj = keyPairs[key]; \
NSAssert([obj respondsToSelector:@selector(setMas_key:)], \
@"Cannot attach mas_key to %@", obj); \
[obj setMas_key:key]; \
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@
#import "NSLayoutConstraint+MASDebugAdditions.h"
#import "MASConstraint.h"
#import "MASLayoutConstraint.h"
@implementation NSLayoutConstraint (MASDebugAdditions)
... ... @@ -66,7 +67,7 @@
#pragma mark - description override
+ (NSString *)descriptionForObject:(id)obj {
if ([obj mas_key]) {
if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
}
return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
... ...
//
// NSObject+MASKeyAdditions.h
// Masonry
//
// Created by Jonas Budelmann on 3/08/13.
// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (MASKeyAdditions)
/**
* a key to associate with this object
*/
@property (nonatomic, strong) id mas_key;
@end
/**
* Allows you to attach keys to objects matching the variable names passed.
*
* view1.mas_key = @"view1", view2.mas_key = @"view2";
*
* is equivalent to:
*
* MASAttachKeys(view1, view2);
*/
#define MASAttachKeys(...) \
NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
for (id key in keyPairs.allKeys) { \
[keyPairs[key] setMas_key:key]; \
}
\ No newline at end of file
//
// NSObject+MASKeyAdditions.m
// Masonry
//
// Created by Jonas Budelmann on 3/08/13.
// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//
#import "NSObject+MASKeyAdditions.h"
#import <objc/runtime.h>
@implementation NSObject (MASKeyAdditions)
- (id)mas_key {
return objc_getAssociatedObject(self, @selector(mas_key));
}
- (void)setMas_key:(id)key {
objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
... ... @@ -32,6 +32,11 @@
@property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
/**
* a key to associate with this view
*/
@property (nonatomic, strong) id mas_key;
/**
Creates a MASConstraintMaker with the callee view. any constraints defined are added to the view or the appropriate superview once the block has finished executing
@param block scope within which you can build up the constraints which you wish to apply to the view.
... ...
... ... @@ -7,6 +7,7 @@
//
#import "UIView+MASAdditions.h"
#import <objc/runtime.h>
@implementation UIView (MASAdditions)
... ... @@ -63,4 +64,14 @@
return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
}
#pragma mark - key
- (id)mas_key {
return objc_getAssociatedObject(self, @selector(mas_key));
}
- (void)setMas_key:(id)key {
objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
\ No newline at end of file
... ...