diff --git a/.travis.yml b/.travis.yml index 765668b7..9b60a467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,17 @@ --- language: objective-c -osx_image: xcode9 +osx_image: xcode12 before_install: - - sudo easy_install cpp-coveralls + - curl -L https://bootstrap.pypa.io/pip/2.7/get-pip.py | sudo python + - sudo pip install cpp-coveralls - gem install xcpretty -N - export LANG=en_US.UTF-8 script: - set -o pipefail - - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS Tests' -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.0' clean test ARCHS=i386 VALID_ARCHS=i386 ONLY_ACTIVE_ARCH=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c - - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS' -configuration Debug -sdk iphonesimulator clean build ARCHS=i386 VALID_ARCHS=i386 ONLY_ACTIVE_ARCH=NO | xcpretty -c - - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry OSX' -configuration Debug clean build | xcpretty -c + - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS Tests' -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=14.0' clean test ARCHS=x86_64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c + - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry' -configuration Debug -sdk iphonesimulator clean build ARCHS=x86_64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO | xcpretty -c + - xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry' -configuration Debug -sdk macosx clean build | xcpretty -c after_success: - ./script/coveralls.sh diff --git a/Masonry.podspec b/Masonry.podspec index 51e2b94b..e4174063 100644 --- a/Masonry.podspec +++ b/Masonry.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = 'Masonry' - s.version = '1.1.0' + s.version = '1.2.0' s.license = 'MIT' s.summary = 'Harness the power of Auto Layout NSLayoutConstraints with a simplified, chainable and expressive syntax.' - s.homepage = 'https://github.com/cloudkite/Masonry' + s.homepage = 'https://github.com/SnapKit/Masonry' s.author = { 'Jonas Budelmann' => 'jonas.budelmann@gmail.com' } s.social_media_url = "http://twitter.com/cloudkite" - s.source = { :git => 'https://github.com/cloudkite/Masonry.git', :tag => "v#{s.version}" } + s.source = { :git => 'https://github.com/SnapKit/Masonry.git', :tag => "v#{s.version}" } s.description = %{ Masonry is a light-weight layout framework which wraps AutoLayout with a nicer syntax. @@ -31,8 +31,8 @@ Pod::Spec.new do |s| s.tvos.frameworks = 'Foundation', 'UIKit' s.osx.frameworks = 'Foundation', 'AppKit' - s.ios.deployment_target = '6.0' # minimum SDK with autolayout - s.osx.deployment_target = '10.7' # minimum SDK with autolayout + s.ios.deployment_target = '9.0' # minimum SDK with autolayout + s.osx.deployment_target = '10.11' # minimum SDK with autolayout s.tvos.deployment_target = '9.0' # minimum SDK with autolayout s.requires_arc = true end diff --git a/Masonry.xcodeproj/project.pbxproj b/Masonry.xcodeproj/project.pbxproj index 1d7d2dab..13656a7c 100644 --- a/Masonry.xcodeproj/project.pbxproj +++ b/Masonry.xcodeproj/project.pbxproj @@ -7,6 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 1539A4A42665991900892F49 /* LayoutGuide+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 15CD2E49266661C000E84D15 /* NSArray+MASShorthandAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CD2E48266661C000E84D15 /* NSArray+MASShorthandAdditions.m */; }; + 15CD2E4B2666620D00E84D15 /* LayoutGuide+MASShorthandAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CD2E4A2666620D00E84D15 /* LayoutGuide+MASShorthandAdditions.m */; }; + 15CD2E4D2666626100E84D15 /* View+MASShorthandAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CD2E4C2666626100E84D15 /* View+MASShorthandAdditions.m */; }; + 15E414912663780600D3D1B6 /* LayoutGuide+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 15E414922663780600D3D1B6 /* LayoutGuide+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */; }; 3AED05BD1AD59FD40053CC65 /* Masonry.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05BC1AD59FD40053CC65 /* Masonry.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3AED05F21AD5A0470053CC65 /* MASCompositeConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05DC1AD5A0470053CC65 /* MASCompositeConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3AED05F31AD5A0470053CC65 /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05DD1AD5A0470053CC65 /* MASCompositeConstraint.m */; }; @@ -30,36 +36,17 @@ 3AED06051AD5A0470053CC65 /* View+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05EF1AD5A0470053CC65 /* View+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3AED06061AD5A0470053CC65 /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05F01AD5A0470053CC65 /* View+MASAdditions.m */; }; 3AED06071AD5A0470053CC65 /* View+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05F11AD5A0470053CC65 /* View+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED060A1AD5A1400053CC65 /* NSArray+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05EB1AD5A0470053CC65 /* NSArray+MASAdditions.m */; }; - 3AED060B1AD5A1400053CC65 /* MASViewAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05E71AD5A0470053CC65 /* MASViewAttribute.m */; }; - 3AED060C1AD5A1400053CC65 /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05E41AD5A0470053CC65 /* MASLayoutConstraint.m */; }; - 3AED060D1AD5A1400053CC65 /* MASConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05DF1AD5A0470053CC65 /* MASConstraint.m */; }; - 3AED060E1AD5A1400053CC65 /* MASViewConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05E91AD5A0470053CC65 /* MASViewConstraint.m */; }; - 3AED060F1AD5A1400053CC65 /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05DD1AD5A0470053CC65 /* MASCompositeConstraint.m */; }; - 3AED06101AD5A1400053CC65 /* MASConstraintMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05E21AD5A0470053CC65 /* MASConstraintMaker.m */; }; - 3AED06111AD5A1400053CC65 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05EE1AD5A0470053CC65 /* NSLayoutConstraint+MASDebugAdditions.m */; }; - 3AED06121AD5A1400053CC65 /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AED05F01AD5A0470053CC65 /* View+MASAdditions.m */; }; - 3AED06151AD5A1400053CC65 /* View+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05EF1AD5A0470053CC65 /* View+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06161AD5A1400053CC65 /* View+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05F11AD5A0470053CC65 /* View+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06171AD5A1400053CC65 /* MASViewAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E61AD5A0470053CC65 /* MASViewAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06181AD5A1400053CC65 /* Masonry.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05BC1AD59FD40053CC65 /* Masonry.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06191AD5A1400053CC65 /* MASLayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E31AD5A0470053CC65 /* MASLayoutConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED061A1AD5A1400053CC65 /* MASViewConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E81AD5A0470053CC65 /* MASViewConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED061B1AD5A1400053CC65 /* NSArray+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05EC1AD5A0470053CC65 /* NSArray+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED061C1AD5A1400053CC65 /* MASConstraintMaker.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E11AD5A0470053CC65 /* MASConstraintMaker.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED061D1AD5A1400053CC65 /* MASConstraint+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E01AD5A0470053CC65 /* MASConstraint+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 3AED061E1AD5A1400053CC65 /* MASUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05E51AD5A0470053CC65 /* MASUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED061F1AD5A1400053CC65 /* NSArray+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05EA1AD5A0470053CC65 /* NSArray+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06201AD5A1400053CC65 /* MASCompositeConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05DC1AD5A0470053CC65 /* MASCompositeConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06211AD5A1400053CC65 /* NSLayoutConstraint+MASDebugAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05ED1AD5A0470053CC65 /* NSLayoutConstraint+MASDebugAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 3AED06221AD5A1400053CC65 /* MASConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05DE1AD5A0470053CC65 /* MASConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4473548D1B39F772004DACCB /* ViewController+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4473548E1B39F772004DACCB /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */; }; - 447354921B3A18B3004DACCB /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */; }; - 447354931B3A18B9004DACCB /* ViewController+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LayoutGuide+MASShorthandAdditions.h"; sourceTree = ""; }; + 15CD2E48266661C000E84D15 /* NSArray+MASShorthandAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MASShorthandAdditions.m"; sourceTree = ""; }; + 15CD2E4A2666620D00E84D15 /* LayoutGuide+MASShorthandAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LayoutGuide+MASShorthandAdditions.m"; sourceTree = ""; }; + 15CD2E4C2666626100E84D15 /* View+MASShorthandAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASShorthandAdditions.m"; sourceTree = ""; }; + 15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LayoutGuide+MASAdditions.h"; sourceTree = ""; }; + 15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "LayoutGuide+MASAdditions.m"; sourceTree = ""; }; 3AED05B71AD59FD40053CC65 /* Masonry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Masonry.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3AED05BB1AD59FD40053CC65 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3AED05BC1AD59FD40053CC65 /* Masonry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = ""; }; @@ -85,7 +72,6 @@ 3AED05EF1AD5A0470053CC65 /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = ""; }; 3AED05F01AD5A0470053CC65 /* View+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASAdditions.m"; sourceTree = ""; }; 3AED05F11AD5A0470053CC65 /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = ""; }; - 3AED06271AD5A1400053CC65 /* Masonry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Masonry.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ViewController+MASAdditions.h"; sourceTree = ""; }; 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ViewController+MASAdditions.m"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -98,13 +84,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 3AED06131AD5A1400053CC65 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -120,7 +99,6 @@ isa = PBXGroup; children = ( 3AED05B71AD59FD40053CC65 /* Masonry.framework */, - 3AED06271AD5A1400053CC65 /* Masonry.framework */, ); name = Products; sourceTree = ""; @@ -133,11 +111,17 @@ 3AED05EF1AD5A0470053CC65 /* View+MASAdditions.h */, 3AED05F01AD5A0470053CC65 /* View+MASAdditions.m */, 3AED05F11AD5A0470053CC65 /* View+MASShorthandAdditions.h */, + 15CD2E4C2666626100E84D15 /* View+MASShorthandAdditions.m */, 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */, 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */, + 15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */, + 15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */, + 1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */, + 15CD2E4A2666620D00E84D15 /* LayoutGuide+MASShorthandAdditions.m */, 3AED05EA1AD5A0470053CC65 /* NSArray+MASAdditions.h */, 3AED05EB1AD5A0470053CC65 /* NSArray+MASAdditions.m */, 3AED05EC1AD5A0470053CC65 /* NSArray+MASShorthandAdditions.h */, + 15CD2E48266661C000E84D15 /* NSArray+MASShorthandAdditions.m */, 3AED05DE1AD5A0470053CC65 /* MASConstraint.h */, 3AED05E01AD5A0470053CC65 /* MASConstraint+Private.h */, 3AED05DF1AD5A0470053CC65 /* MASConstraint.m */, @@ -176,6 +160,8 @@ 3AED06051AD5A0470053CC65 /* View+MASAdditions.h in Headers */, 3AED06071AD5A0470053CC65 /* View+MASShorthandAdditions.h in Headers */, 4473548D1B39F772004DACCB /* ViewController+MASAdditions.h in Headers */, + 15E414912663780600D3D1B6 /* LayoutGuide+MASAdditions.h in Headers */, + 1539A4A42665991900892F49 /* LayoutGuide+MASShorthandAdditions.h in Headers */, 3AED05FC1AD5A0470053CC65 /* MASViewAttribute.h in Headers */, 3AED05BD1AD59FD40053CC65 /* Masonry.h in Headers */, 3AED05F91AD5A0470053CC65 /* MASLayoutConstraint.h in Headers */, @@ -191,34 +177,12 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 3AED06141AD5A1400053CC65 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 3AED06151AD5A1400053CC65 /* View+MASAdditions.h in Headers */, - 3AED06161AD5A1400053CC65 /* View+MASShorthandAdditions.h in Headers */, - 3AED06171AD5A1400053CC65 /* MASViewAttribute.h in Headers */, - 3AED06181AD5A1400053CC65 /* Masonry.h in Headers */, - 3AED06191AD5A1400053CC65 /* MASLayoutConstraint.h in Headers */, - 3AED061A1AD5A1400053CC65 /* MASViewConstraint.h in Headers */, - 3AED061B1AD5A1400053CC65 /* NSArray+MASShorthandAdditions.h in Headers */, - 3AED061C1AD5A1400053CC65 /* MASConstraintMaker.h in Headers */, - 3AED061E1AD5A1400053CC65 /* MASUtilities.h in Headers */, - 3AED061F1AD5A1400053CC65 /* NSArray+MASAdditions.h in Headers */, - 3AED06201AD5A1400053CC65 /* MASCompositeConstraint.h in Headers */, - 447354931B3A18B9004DACCB /* ViewController+MASAdditions.h in Headers */, - 3AED06221AD5A1400053CC65 /* MASConstraint.h in Headers */, - 3AED061D1AD5A1400053CC65 /* MASConstraint+Private.h in Headers */, - 3AED06211AD5A1400053CC65 /* NSLayoutConstraint+MASDebugAdditions.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 3AED05B61AD59FD40053CC65 /* Masonry iOS */ = { + 3AED05B61AD59FD40053CC65 /* Masonry */ = { isa = PBXNativeTarget; - buildConfigurationList = 3AED05CD1AD59FD40053CC65 /* Build configuration list for PBXNativeTarget "Masonry iOS" */; + buildConfigurationList = 3AED05CD1AD59FD40053CC65 /* Build configuration list for PBXNativeTarget "Masonry" */; buildPhases = ( 3AED05B21AD59FD40053CC65 /* Sources */, 3AED05B31AD59FD40053CC65 /* Frameworks */, @@ -229,36 +193,18 @@ ); dependencies = ( ); - name = "Masonry iOS"; + name = Masonry; productName = Masonry; productReference = 3AED05B71AD59FD40053CC65 /* Masonry.framework */; productType = "com.apple.product-type.framework"; }; - 3AED06081AD5A1400053CC65 /* Masonry OSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = 3AED06241AD5A1400053CC65 /* Build configuration list for PBXNativeTarget "Masonry OSX" */; - buildPhases = ( - 3AED06091AD5A1400053CC65 /* Sources */, - 3AED06131AD5A1400053CC65 /* Frameworks */, - 3AED06141AD5A1400053CC65 /* Headers */, - 3AED06231AD5A1400053CC65 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Masonry OSX"; - productName = Masonry; - productReference = 3AED06271AD5A1400053CC65 /* Masonry.framework */; - productType = "com.apple.product-type.framework"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 3AED05AE1AD59FD40053CC65 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1250; ORGANIZATIONNAME = "Jonas Budelmann"; TargetAttributes = { 3AED05B61AD59FD40053CC65 = { @@ -271,6 +217,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 3AED05AD1AD59FD40053CC65; @@ -278,8 +225,7 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 3AED05B61AD59FD40053CC65 /* Masonry iOS */, - 3AED06081AD5A1400053CC65 /* Masonry OSX */, + 3AED05B61AD59FD40053CC65 /* Masonry */, ); }; /* End PBXProject section */ @@ -292,13 +238,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 3AED06231AD5A1400053CC65 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -308,9 +247,13 @@ files = ( 3AED06011AD5A0470053CC65 /* NSArray+MASAdditions.m in Sources */, 3AED05FD1AD5A0470053CC65 /* MASViewAttribute.m in Sources */, + 15CD2E4D2666626100E84D15 /* View+MASShorthandAdditions.m in Sources */, 4473548E1B39F772004DACCB /* ViewController+MASAdditions.m in Sources */, + 15E414922663780600D3D1B6 /* LayoutGuide+MASAdditions.m in Sources */, + 15CD2E49266661C000E84D15 /* NSArray+MASShorthandAdditions.m in Sources */, 3AED05FA1AD5A0470053CC65 /* MASLayoutConstraint.m in Sources */, 3AED05F51AD5A0470053CC65 /* MASConstraint.m in Sources */, + 15CD2E4B2666620D00E84D15 /* LayoutGuide+MASShorthandAdditions.m in Sources */, 3AED05FF1AD5A0470053CC65 /* MASViewConstraint.m in Sources */, 3AED05F31AD5A0470053CC65 /* MASCompositeConstraint.m in Sources */, 3AED05F81AD5A0470053CC65 /* MASConstraintMaker.m in Sources */, @@ -319,23 +262,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 3AED06091AD5A1400053CC65 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 3AED060A1AD5A1400053CC65 /* NSArray+MASAdditions.m in Sources */, - 3AED060B1AD5A1400053CC65 /* MASViewAttribute.m in Sources */, - 3AED060C1AD5A1400053CC65 /* MASLayoutConstraint.m in Sources */, - 3AED060D1AD5A1400053CC65 /* MASConstraint.m in Sources */, - 3AED060E1AD5A1400053CC65 /* MASViewConstraint.m in Sources */, - 3AED060F1AD5A1400053CC65 /* MASCompositeConstraint.m in Sources */, - 447354921B3A18B3004DACCB /* ViewController+MASAdditions.m in Sources */, - 3AED06101AD5A1400053CC65 /* MASConstraintMaker.m in Sources */, - 3AED06111AD5A1400053CC65 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */, - 3AED06121AD5A1400053CC65 /* View+MASAdditions.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ @@ -352,14 +278,17 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -386,12 +315,15 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; TARGETED_DEVICE_FAMILY = "1,2"; + TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; + WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Debug; }; @@ -408,14 +340,17 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -435,12 +370,15 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; TARGETED_DEVICE_FAMILY = "1,2"; + TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; + WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Release; }; @@ -455,10 +393,12 @@ INFOPLIST_FILE = Masonry/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Masonry; - SDKROOT = iphoneos; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; }; name = Debug; }; @@ -473,46 +413,12 @@ INFOPLIST_FILE = Masonry/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = staticlib; PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Masonry; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 3AED06251AD5A1400053CC65 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = Masonry/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = Masonry; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 3AED06261AD5A1400053CC65 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = Masonry/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.cloudling.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = Masonry; - SDKROOT = macosx; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; }; name = Release; }; @@ -528,7 +434,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 3AED05CD1AD59FD40053CC65 /* Build configuration list for PBXNativeTarget "Masonry iOS" */ = { + 3AED05CD1AD59FD40053CC65 /* Build configuration list for PBXNativeTarget "Masonry" */ = { isa = XCConfigurationList; buildConfigurations = ( 3AED05CE1AD59FD40053CC65 /* Debug */, @@ -537,15 +443,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 3AED06241AD5A1400053CC65 /* Build configuration list for PBXNativeTarget "Masonry OSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 3AED06251AD5A1400053CC65 /* Debug */, - 3AED06261AD5A1400053CC65 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = 3AED05AE1AD59FD40053CC65 /* Project object */; diff --git a/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry OSX.xcscheme b/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry OSX.xcscheme deleted file mode 100644 index 17d12e9b..00000000 --- a/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry OSX.xcscheme +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry iOS.xcscheme b/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry.xcscheme similarity index 78% rename from Masonry.xcodeproj/xcshareddata/xcschemes/Masonry iOS.xcscheme rename to Masonry.xcodeproj/xcshareddata/xcschemes/Masonry.xcscheme index 61c34a76..124167eb 100644 --- a/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry iOS.xcscheme +++ b/Masonry.xcodeproj/xcshareddata/xcschemes/Masonry.xcscheme @@ -1,6 +1,6 @@ @@ -26,35 +26,20 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - - - - - diff --git a/Masonry/LayoutGuide+MASAdditions.h b/Masonry/LayoutGuide+MASAdditions.h new file mode 100644 index 00000000..d01c6dc9 --- /dev/null +++ b/Masonry/LayoutGuide+MASAdditions.h @@ -0,0 +1,65 @@ +// +// LayoutGuide+MASAdditions.h +// Masonry +// +// Created by v on 2021/5/30. +// Copyright © 2021 Jonas Budelmann. All rights reserved. +// + +#import "MASUtilities.h" +#import "MASConstraintMaker.h" +#import "MASViewAttribute.h" + +NS_ASSUME_NONNULL_BEGIN + +API_AVAILABLE(macos(10.11), ios(9.0)) +@interface MASLayoutGuide (MASAdditions) + +@property (nonatomic, strong, readonly) MASViewAttribute *mas_left; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_top; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_right; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_width; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_height; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; +@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; + +@property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); + +/** + * 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. + * + * @return Array of created MASConstraints + */ +- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(id make))block; + +/** + * 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. + * If an existing constraint exists then it will be updated instead. + * + * @param block scope within which you can build up the constraints which you wish to apply to the view. + * + * @return Array of created/updated MASConstraints + */ +- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(id make))block; + +/** + * 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. + * All constraints previously installed for the view will be removed. + * + * @param block scope within which you can build up the constraints which you wish to apply to the view. + * + * @return Array of created/updated MASConstraints + */ +- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(id make))block; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Masonry/LayoutGuide+MASAdditions.m b/Masonry/LayoutGuide+MASAdditions.m new file mode 100644 index 00000000..f4c82ce8 --- /dev/null +++ b/Masonry/LayoutGuide+MASAdditions.m @@ -0,0 +1,83 @@ +// +// LayoutGuide+MASAdditions.m +// Masonry +// +// Created by v on 2021/5/30. +// Copyright © 2021 Jonas Budelmann. All rights reserved. +// + +#import "LayoutGuide+MASAdditions.h" +#import + + +@implementation MASLayoutGuide (MASAdditions) + +- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(id make))block { + MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self]; + block(constraintMaker); + return [constraintMaker install]; +} + +- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(id make))block { + MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self]; + constraintMaker.updateExisting = YES; + block(constraintMaker); + return [constraintMaker install]; +} + +- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(id make))block { + MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self]; + constraintMaker.removeExisting = YES; + block(constraintMaker); + return [constraintMaker install]; +} + +#pragma mark - NSLayoutAttribute properties + +- (MASViewAttribute *)mas_left { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeLeft]; +} + +- (MASViewAttribute *)mas_top { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeTop]; +} + +- (MASViewAttribute *)mas_right { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeRight]; +} + +- (MASViewAttribute *)mas_bottom { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeBottom]; +} + +- (MASViewAttribute *)mas_leading { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeLeading]; +} + +- (MASViewAttribute *)mas_trailing { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeTrailing]; +} + +- (MASViewAttribute *)mas_width { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeWidth]; +} + +- (MASViewAttribute *)mas_height { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeHeight]; +} + +- (MASViewAttribute *)mas_centerX { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeCenterX]; +} + +- (MASViewAttribute *)mas_centerY { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeCenterY]; +} + +- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute { + return ^(NSLayoutAttribute attr) { + return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:attr]; + }; +} + +@end diff --git a/Masonry/LayoutGuide+MASShorthandAdditions.h b/Masonry/LayoutGuide+MASShorthandAdditions.h new file mode 100644 index 00000000..ec8f250a --- /dev/null +++ b/Masonry/LayoutGuide+MASShorthandAdditions.h @@ -0,0 +1,43 @@ +// +// LayoutGuide+MASShorthandAdditions.h +// Masonry +// +// Created by v on 2021/6/1. +// Copyright © 2021 Jonas Budelmann. All rights reserved. +// + +#import "LayoutGuide+MASAdditions.h" + +NS_ASSUME_NONNULL_BEGIN + +#ifdef MAS_SHORTHAND + +/** + * Shorthand view additions without the 'mas_' prefixes, + * only enabled if MAS_SHORTHAND is defined + */ +API_AVAILABLE(macos(10.11), ios(9.0)) +@interface MASLayoutGuide (MASShorthandAdditions) + +@property (nonatomic, strong, readonly) MASViewAttribute *left; +@property (nonatomic, strong, readonly) MASViewAttribute *top; +@property (nonatomic, strong, readonly) MASViewAttribute *right; +@property (nonatomic, strong, readonly) MASViewAttribute *bottom; +@property (nonatomic, strong, readonly) MASViewAttribute *leading; +@property (nonatomic, strong, readonly) MASViewAttribute *trailing; +@property (nonatomic, strong, readonly) MASViewAttribute *width; +@property (nonatomic, strong, readonly) MASViewAttribute *height; +@property (nonatomic, strong, readonly) MASViewAttribute *centerX; +@property (nonatomic, strong, readonly) MASViewAttribute *centerY; + +@property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); + +- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; +- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; +- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; + +@end + +#endif + +NS_ASSUME_NONNULL_END diff --git a/Masonry/LayoutGuide+MASShorthandAdditions.m b/Masonry/LayoutGuide+MASShorthandAdditions.m new file mode 100644 index 00000000..b4ece899 --- /dev/null +++ b/Masonry/LayoutGuide+MASShorthandAdditions.m @@ -0,0 +1,40 @@ +// +// LayoutGuide+MASShorthandAdditions.m +// Masonry +// +// Created by v on 2021/6/1. +// Copyright © 2021 Jonas Budelmann. All rights reserved. +// + +#import "LayoutGuide+MASShorthandAdditions.h" + +@implementation MASLayoutGuide (MASShorthandAdditions) + +MAS_ATTR_FORWARD(top); +MAS_ATTR_FORWARD(left); +MAS_ATTR_FORWARD(bottom); +MAS_ATTR_FORWARD(right); +MAS_ATTR_FORWARD(leading); +MAS_ATTR_FORWARD(trailing); +MAS_ATTR_FORWARD(width); +MAS_ATTR_FORWARD(height); +MAS_ATTR_FORWARD(centerX); +MAS_ATTR_FORWARD(centerY); + +- (MASViewAttribute *(^)(NSLayoutAttribute))attribute { + return [self mas_attribute]; +} + +- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_makeConstraints:block]; +} + +- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_updateConstraints:block]; +} + +- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_remakeConstraints:block]; +} + +@end diff --git a/Masonry/MASConstraint.m b/Masonry/MASConstraint.m index b8841e58..099d6dfe 100644 --- a/Masonry/MASConstraint.m +++ b/Masonry/MASConstraint.m @@ -212,7 +212,7 @@ - (MASConstraint *)centerY { } - (MASConstraint *)baseline { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; } - (MASConstraint *)firstBaseline { diff --git a/Masonry/MASConstraintMaker.h b/Masonry/MASConstraintMaker.h index 9a0bc8df..20e82984 100644 --- a/Masonry/MASConstraintMaker.h +++ b/Masonry/MASConstraintMaker.h @@ -20,10 +20,11 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { MASAttributeHeight = 1 << NSLayoutAttributeHeight, MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, - MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline, MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline, + + MASAttributeBaseline = MASAttributeLastBaseline, #if TARGET_OS_IPHONE || TARGET_OS_TV @@ -40,12 +41,48 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { }; +@protocol MASLayoutConstraint + +@property (nonatomic, strong, readonly) MASConstraint *left; +@property (nonatomic, strong, readonly) MASConstraint *top; +@property (nonatomic, strong, readonly) MASConstraint *right; +@property (nonatomic, strong, readonly) MASConstraint *bottom; +@property (nonatomic, strong, readonly) MASConstraint *leading; +@property (nonatomic, strong, readonly) MASConstraint *trailing; +@property (nonatomic, strong, readonly) MASConstraint *width; +@property (nonatomic, strong, readonly) MASConstraint *height; +@property (nonatomic, strong, readonly) MASConstraint *centerX; +@property (nonatomic, strong, readonly) MASConstraint *centerY; + +/** + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges + * which generates the appropriate MASViewConstraint children (top, left, bottom, right) + * with the first item set to the makers associated view + */ +@property (nonatomic, strong, readonly) MASConstraint *edges; + +/** + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize + * which generates the appropriate MASViewConstraint children (width, height) + * with the first item set to the makers associated view + */ +@property (nonatomic, strong, readonly) MASConstraint *size; + +/** + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter + * which generates the appropriate MASViewConstraint children (centerX, centerY) + * with the first item set to the makers associated view + */ +@property (nonatomic, strong, readonly) MASConstraint *center; + +@end + /** * Provides factory methods for creating MASConstraints. * Constraints are collected until they are ready to be installed * */ -@interface MASConstraintMaker : NSObject +@interface MASConstraintMaker : NSObject /** * The following properties return a new MASViewConstraint @@ -126,6 +163,8 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { */ - (id)initWithView:(MAS_VIEW *)view; +- (id)initWithLayoutGuide:(MASLayoutGuide *)layoutGuide API_AVAILABLE(macos(10.11), ios(9.0)); + /** * Calls install method on any MASConstraints which have been created by this maker * diff --git a/Masonry/MASConstraintMaker.m b/Masonry/MASConstraintMaker.m index 26d377be..8ac87785 100644 --- a/Masonry/MASConstraintMaker.m +++ b/Masonry/MASConstraintMaker.m @@ -12,10 +12,12 @@ #import "MASConstraint+Private.h" #import "MASViewAttribute.h" #import "View+MASAdditions.h" +#import "LayoutGuide+MASAdditions.h" @interface MASConstraintMaker () @property (nonatomic, weak) MAS_VIEW *view; +@property (nullable, nonatomic, weak) MASLayoutGuide *item; @property (nonatomic, strong) NSMutableArray *constraints; @end @@ -25,16 +27,34 @@ @implementation MASConstraintMaker - (id)initWithView:(MAS_VIEW *)view { self = [super init]; if (!self) return nil; - + self.view = view; self.constraints = NSMutableArray.new; - + + return self; +} + +- (id)initWithLayoutGuide:(MASLayoutGuide *)layoutGuide { + NSAssert(layoutGuide.owningView != nil, @"layoutGuide's owningView must not be nil"); + self = [super init]; + if (!self) return nil; + + self.view = layoutGuide.owningView; + self.item = layoutGuide; + self.constraints = NSMutableArray.new; + return self; } - (NSArray *)install { if (self.removeExisting) { - NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; + NSArray *installedConstraints; + if ([self.item isKindOfClass:MASLayoutGuide.class]) { + installedConstraints = [MASViewConstraint installedConstraintsForLayoutGuide:self.item]; + } else { + installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; + } + for (MASConstraint *constraint in installedConstraints) { [constraint uninstall]; } @@ -57,7 +77,7 @@ - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(M } - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute]; + MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view item:self.item layoutAttribute:layoutAttribute]; MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; if ([constraint isKindOfClass:MASViewConstraint.class]) { //replace with composite constraint @@ -89,17 +109,19 @@ - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs { NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)"); NSMutableArray *attributes = [NSMutableArray array]; + +#define layoutItem ((MAS_VIEW *)(self.item ?: self.view)) - if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left]; - if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right]; - if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top]; - if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom]; - if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading]; - if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing]; - if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width]; - if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height]; - if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX]; - if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; + if (attrs & MASAttributeLeft) [attributes addObject:layoutItem.mas_left]; + if (attrs & MASAttributeRight) [attributes addObject:layoutItem.mas_right]; + if (attrs & MASAttributeTop) [attributes addObject:layoutItem.mas_top]; + if (attrs & MASAttributeBottom) [attributes addObject:layoutItem.mas_bottom]; + if (attrs & MASAttributeLeading) [attributes addObject:layoutItem.mas_leading]; + if (attrs & MASAttributeTrailing) [attributes addObject:layoutItem.mas_trailing]; + if (attrs & MASAttributeWidth) [attributes addObject:layoutItem.mas_width]; + if (attrs & MASAttributeHeight) [attributes addObject:layoutItem.mas_height]; + if (attrs & MASAttributeCenterX) [attributes addObject:layoutItem.mas_centerX]; + if (attrs & MASAttributeCenterY) [attributes addObject:layoutItem.mas_centerY]; if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline]; if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline]; @@ -176,7 +198,7 @@ - (MASConstraint *)centerY { } - (MASConstraint *)baseline { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; } - (MASConstraint *(^)(MASAttribute))attributes { diff --git a/Masonry/MASUtilities.h b/Masonry/MASUtilities.h index 1dbfd938..393f76f8 100644 --- a/Masonry/MASUtilities.h +++ b/Masonry/MASUtilities.h @@ -14,6 +14,7 @@ #import #define MAS_VIEW UIView + #define MASLayoutGuide UILayoutGuide #define MAS_VIEW_CONTROLLER UIViewController #define MASEdgeInsets UIEdgeInsets @@ -28,6 +29,7 @@ #import #define MAS_VIEW NSView + #define MASLayoutGuide NSLayoutGuide #define MASEdgeInsets NSEdgeInsets typedef NSLayoutPriority MASLayoutPriority; @@ -134,3 +136,13 @@ static inline id _MASBoxValue(const char *type, ...) { } #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) + +#define MAS_ATTR_FORWARD(attr) \ +- (MASViewAttribute *)attr { \ + return [self mas_##attr]; \ +} + +#define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \ +- (MASViewAttribute *)attr available { \ + return [self mas_##attr]; \ +} diff --git a/Masonry/MASViewAttribute.m b/Masonry/MASViewAttribute.m index e573e8bd..e55163ef 100644 --- a/Masonry/MASViewAttribute.m +++ b/Masonry/MASViewAttribute.m @@ -20,7 +20,7 @@ - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttri if (!self) return nil; _view = view; - _item = item; + _item = item?:view; _layoutAttribute = layoutAttribute; return self; diff --git a/Masonry/MASViewConstraint.h b/Masonry/MASViewConstraint.h index ec390d15..b7d0ebac 100644 --- a/Masonry/MASViewConstraint.h +++ b/Masonry/MASViewConstraint.h @@ -45,4 +45,6 @@ */ + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; ++ (NSArray *)installedConstraintsForLayoutGuide:(MASLayoutGuide *)layoutGuide API_AVAILABLE(macos(10.11), ios(9.0)); + @end diff --git a/Masonry/MASViewConstraint.m b/Masonry/MASViewConstraint.m index af3f0b44..591ca367 100644 --- a/Masonry/MASViewConstraint.m +++ b/Masonry/MASViewConstraint.m @@ -35,6 +35,28 @@ - (NSMutableSet *)mas_installedConstraints { @end +@interface MASLayoutGuide (MASConstraints) + +@property (nonatomic, readonly) NSMutableSet *mas_installedConstraints; + +@end + +@implementation MASLayoutGuide (MASConstraints) + +static char kInstalledConstraintsKey; + +- (NSMutableSet *)mas_installedConstraints { + NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey); + if (!constraints) { + constraints = [NSMutableSet set]; + objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + return constraints; +} + +@end + + @interface MASViewConstraint () @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute; @@ -81,6 +103,10 @@ + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view { return [view.mas_installedConstraints allObjects]; } ++ (NSArray *)installedConstraintsForLayoutGuide:(MASLayoutGuide *)layoutGuide { + return [layoutGuide.mas_installedConstraints allObjects]; +} + #pragma mark - Private - (void)setLayoutConstant:(CGFloat)layoutConstant { @@ -121,16 +147,27 @@ - (BOOL)hasBeenInstalled { - (void)setSecondViewAttribute:(id)secondViewAttribute { if ([secondViewAttribute isKindOfClass:NSValue.class]) { + if ([self.firstViewAttribute.item isKindOfClass:MASLayoutGuide.class]) { + if (!self.firstViewAttribute.isSizeAttribute) { + _secondViewAttribute = [[MASViewAttribute alloc] initWithView:self.firstViewAttribute.view + layoutAttribute:self.firstViewAttribute.layoutAttribute]; + } + } + [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]) { MASViewAttribute *attr = secondViewAttribute; if (attr.layoutAttribute == NSLayoutAttributeNotAnAttribute) { - _secondViewAttribute = [[MASViewAttribute alloc] initWithView:attr.view item:attr.item layoutAttribute:self.firstViewAttribute.layoutAttribute];; + _secondViewAttribute = [[MASViewAttribute alloc] initWithView:attr.view item:attr.item layoutAttribute:self.firstViewAttribute.layoutAttribute]; } else { _secondViewAttribute = secondViewAttribute; } + } else if ([secondViewAttribute isKindOfClass:MASLayoutGuide.class]) { + _secondViewAttribute = [[MASViewAttribute alloc] initWithView:((MASLayoutGuide *)secondViewAttribute).owningView + item:secondViewAttribute + layoutAttribute:self.firstViewAttribute.layoutAttribute]; } else { NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute); } @@ -363,8 +400,13 @@ - (void)install { existingConstraint.constant = layoutConstraint.constant; self.layoutConstraint = existingConstraint; } else { - [self.installedView addConstraint:layoutConstraint]; self.layoutConstraint = layoutConstraint; + if ([self supportsActiveProperty]) { + layoutConstraint.active = YES; + } else { + [self.installedView addConstraint:layoutConstraint]; + } + [firstLayoutItem.mas_installedConstraints addObject:self]; } } @@ -392,15 +434,13 @@ - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layout - (void)uninstall { if ([self supportsActiveProperty]) { self.layoutConstraint.active = NO; - [self.firstViewAttribute.view.mas_installedConstraints removeObject:self]; - return; + } else { + [self.installedView removeConstraint:self.layoutConstraint]; } - - [self.installedView removeConstraint:self.layoutConstraint]; + + [self.firstViewAttribute.view.mas_installedConstraints removeObject:self]; self.layoutConstraint = nil; self.installedView = nil; - - [self.firstViewAttribute.view.mas_installedConstraints removeObject:self]; } @end diff --git a/Masonry/Masonry.h b/Masonry/Masonry.h index d1bd579d..b85dae49 100644 --- a/Masonry/Masonry.h +++ b/Masonry/Masonry.h @@ -18,6 +18,8 @@ FOUNDATION_EXPORT const unsigned char MasonryVersionString[]; #import "View+MASAdditions.h" #import "View+MASShorthandAdditions.h" #import "ViewController+MASAdditions.h" +#import "LayoutGuide+MASAdditions.h" +#import "LayoutGuide+MASShorthandAdditions.h" #import "NSArray+MASAdditions.h" #import "NSArray+MASShorthandAdditions.h" #import "MASConstraint.h" diff --git a/Masonry/NSArray+MASAdditions.m b/Masonry/NSArray+MASAdditions.m index 831d8cda..f31390ae 100644 --- a/Masonry/NSArray+MASAdditions.m +++ b/Masonry/NSArray+MASAdditions.m @@ -11,7 +11,7 @@ @implementation NSArray (MASAdditions) -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { +- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block { NSMutableArray *constraints = [NSMutableArray array]; for (MAS_VIEW *view in self) { NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); @@ -20,7 +20,7 @@ - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { return constraints; } -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { +- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block { NSMutableArray *constraints = [NSMutableArray array]; for (MAS_VIEW *view in self) { NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); @@ -29,7 +29,7 @@ - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { return constraints; } -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { +- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block { NSMutableArray *constraints = [NSMutableArray array]; for (MAS_VIEW *view in self) { NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); diff --git a/Masonry/NSArray+MASShorthandAdditions.h b/Masonry/NSArray+MASShorthandAdditions.h index 8b473697..cd63f437 100644 --- a/Masonry/NSArray+MASShorthandAdditions.h +++ b/Masonry/NSArray+MASShorthandAdditions.h @@ -22,20 +22,4 @@ @end -@implementation NSArray (MASShorthandAdditions) - -- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_makeConstraints:block]; -} - -- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_updateConstraints:block]; -} - -- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_remakeConstraints:block]; -} - -@end - #endif diff --git a/Masonry/NSArray+MASShorthandAdditions.m b/Masonry/NSArray+MASShorthandAdditions.m new file mode 100644 index 00000000..b777b8e7 --- /dev/null +++ b/Masonry/NSArray+MASShorthandAdditions.m @@ -0,0 +1,25 @@ +// +// NSArray+MASShorthandAdditions.m +// Masonry +// +// Created by Jonas Budelmann on 22/07/13. +// Copyright (c) 2013 Jonas Budelmann. All rights reserved. +// + +#import "NSArray+MASShorthandAdditions.h" + +@implementation NSArray (MASShorthandAdditions) + +- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { + return [self mas_makeConstraints:block]; +} + +- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { + return [self mas_updateConstraints:block]; +} + +- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { + return [self mas_remakeConstraints:block]; +} + +@end diff --git a/Masonry/NSLayoutConstraint+MASDebugAdditions.m b/Masonry/NSLayoutConstraint+MASDebugAdditions.m index f6c43f54..b365fd7e 100644 --- a/Masonry/NSLayoutConstraint+MASDebugAdditions.m +++ b/Masonry/NSLayoutConstraint+MASDebugAdditions.m @@ -42,7 +42,7 @@ + (NSDictionary *)layoutAttributeDescriptionsByValue { @(NSLayoutAttributeHeight) : @"height", @(NSLayoutAttributeCenterX) : @"centerX", @(NSLayoutAttributeCenterY) : @"centerY", - @(NSLayoutAttributeBaseline) : @"baseline", + @(NSLayoutAttributeFirstBaseline) : @"firstBaseline", @(NSLayoutAttributeLastBaseline) : @"lastBaseline", diff --git a/Masonry/View+MASAdditions.h b/Masonry/View+MASAdditions.h index 00477c1c..59529ccf 100644 --- a/Masonry/View+MASAdditions.h +++ b/Masonry/View+MASAdditions.h @@ -1,5 +1,5 @@ // -// UIView+MASAdditions.h +// View+MASAdditions.h // Masonry // // Created by Jonas Budelmann on 20/07/13. @@ -46,17 +46,17 @@ @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins; @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY API_AVAILABLE(ios(11.0)); #endif @@ -72,7 +72,7 @@ * * @return returns nil if common superview could not be found */ -- (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; +- (__kindof MAS_VIEW *)mas_closestCommonSuperview:(MAS_VIEW *)view; /** * Creates a MASConstraintMaker with the callee view. diff --git a/Masonry/View+MASAdditions.m b/Masonry/View+MASAdditions.m index b99316ad..f50814c1 100644 --- a/Masonry/View+MASAdditions.m +++ b/Masonry/View+MASAdditions.m @@ -1,5 +1,5 @@ // -// UIView+MASAdditions.m +// View+MASAdditions.m // Masonry // // Created by Jonas Budelmann on 20/07/13. @@ -11,14 +11,14 @@ @implementation MAS_VIEW (MASAdditions) -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { +- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { self.translatesAutoresizingMaskIntoConstraints = NO; MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; block(constraintMaker); return [constraintMaker install]; } -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { +- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { self.translatesAutoresizingMaskIntoConstraints = NO; MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; constraintMaker.updateExisting = YES; @@ -26,7 +26,7 @@ - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { return [constraintMaker install]; } -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { +- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block { self.translatesAutoresizingMaskIntoConstraints = NO; MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; constraintMaker.removeExisting = YES; @@ -77,11 +77,10 @@ - (MASViewAttribute *)mas_centerY { } - (MASViewAttribute *)mas_baseline { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; + return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline]; } -- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute -{ +- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute { return ^(NSLayoutAttribute attr) { return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; }; @@ -186,20 +185,15 @@ - (void)setMas_key:(id)key { #pragma mark - heirachy -- (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { - MAS_VIEW *closestCommonSuperview = nil; - +- (__kindof MAS_VIEW *)mas_closestCommonSuperview:(MAS_VIEW *)view { + MAS_VIEW *closestCommonSuperview = self; MAS_VIEW *secondViewSuperview = view; - while (!closestCommonSuperview && secondViewSuperview) { - MAS_VIEW *firstViewSuperview = self; - while (!closestCommonSuperview && firstViewSuperview) { - if (secondViewSuperview == firstViewSuperview) { - closestCommonSuperview = secondViewSuperview; - } - firstViewSuperview = firstViewSuperview.superview; - } - secondViewSuperview = secondViewSuperview.superview; + // O(a+b) + while (closestCommonSuperview != secondViewSuperview) { + closestCommonSuperview = !closestCommonSuperview ? view : closestCommonSuperview.superview; + secondViewSuperview = !secondViewSuperview ? self : secondViewSuperview.superview; } + return closestCommonSuperview; } diff --git a/Masonry/View+MASShorthandAdditions.h b/Masonry/View+MASShorthandAdditions.h index 8e375ee3..5d143828 100644 --- a/Masonry/View+MASShorthandAdditions.h +++ b/Masonry/View+MASShorthandAdditions.h @@ -1,5 +1,5 @@ // -// UIView+MASShorthandAdditions.h +// View+MASShorthandAdditions.h // Masonry // // Created by Jonas Budelmann on 22/07/13. @@ -47,16 +47,16 @@ #if TARGET_OS_IPHONE || TARGET_OS_TV -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX API_AVAILABLE(ios(11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY API_AVAILABLE(ios(11.0)); #endif @@ -66,73 +66,4 @@ @end -#define MAS_ATTR_FORWARD(attr) \ -- (MASViewAttribute *)attr { \ - return [self mas_##attr]; \ -} - -#define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \ -- (MASViewAttribute *)attr available { \ - return [self mas_##attr]; \ -} - -@implementation MAS_VIEW (MASShorthandAdditions) - -MAS_ATTR_FORWARD(top); -MAS_ATTR_FORWARD(left); -MAS_ATTR_FORWARD(bottom); -MAS_ATTR_FORWARD(right); -MAS_ATTR_FORWARD(leading); -MAS_ATTR_FORWARD(trailing); -MAS_ATTR_FORWARD(width); -MAS_ATTR_FORWARD(height); -MAS_ATTR_FORWARD(centerX); -MAS_ATTR_FORWARD(centerY); -MAS_ATTR_FORWARD(baseline); - -MAS_ATTR_FORWARD(firstBaseline); -MAS_ATTR_FORWARD(lastBaseline); - -#if TARGET_OS_IPHONE || TARGET_OS_TV - -MAS_ATTR_FORWARD(leftMargin); -MAS_ATTR_FORWARD(rightMargin); -MAS_ATTR_FORWARD(topMargin); -MAS_ATTR_FORWARD(bottomMargin); -MAS_ATTR_FORWARD(leadingMargin); -MAS_ATTR_FORWARD(trailingMargin); -MAS_ATTR_FORWARD(centerXWithinMargins); -MAS_ATTR_FORWARD(centerYWithinMargins); - -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0)); -MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0)); - -#endif - -- (MASViewAttribute *(^)(NSLayoutAttribute))attribute { - return [self mas_attribute]; -} - -- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { - return [self mas_makeConstraints:block]; -} - -- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { - return [self mas_updateConstraints:block]; -} - -- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { - return [self mas_remakeConstraints:block]; -} - -@end - #endif diff --git a/Masonry/View+MASShorthandAdditions.m b/Masonry/View+MASShorthandAdditions.m new file mode 100644 index 00000000..4b1260a7 --- /dev/null +++ b/Masonry/View+MASShorthandAdditions.m @@ -0,0 +1,68 @@ +// +// View+MASShorthandAdditions.m +// Masonry +// +// Created by Jonas Budelmann on 22/07/13. +// Copyright (c) 2013 Jonas Budelmann. All rights reserved. +// + +#import "View+MASShorthandAdditions.h" + +@implementation MAS_VIEW (MASShorthandAdditions) + +MAS_ATTR_FORWARD(top); +MAS_ATTR_FORWARD(left); +MAS_ATTR_FORWARD(bottom); +MAS_ATTR_FORWARD(right); +MAS_ATTR_FORWARD(leading); +MAS_ATTR_FORWARD(trailing); +MAS_ATTR_FORWARD(width); +MAS_ATTR_FORWARD(height); +MAS_ATTR_FORWARD(centerX); +MAS_ATTR_FORWARD(centerY); +MAS_ATTR_FORWARD(baseline); + +MAS_ATTR_FORWARD(firstBaseline); +MAS_ATTR_FORWARD(lastBaseline); + +#if TARGET_OS_IPHONE || TARGET_OS_TV + +MAS_ATTR_FORWARD(leftMargin); +MAS_ATTR_FORWARD(rightMargin); +MAS_ATTR_FORWARD(topMargin); +MAS_ATTR_FORWARD(bottomMargin); +MAS_ATTR_FORWARD(leadingMargin); +MAS_ATTR_FORWARD(trailingMargin); +MAS_ATTR_FORWARD(centerXWithinMargins); +MAS_ATTR_FORWARD(centerYWithinMargins); + +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, API_AVAILABLE(ios(11.0))); +MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, API_AVAILABLE(ios(11.0))); + +#endif + +- (MASViewAttribute *(^)(NSLayoutAttribute))attribute { + return [self mas_attribute]; +} + +- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_makeConstraints:block]; +} + +- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_updateConstraints:block]; +} + +- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block { + return [self mas_remakeConstraints:block]; +} + +@end diff --git a/Masonry/ViewController+MASAdditions.h b/Masonry/ViewController+MASAdditions.h index 564654af..4b44e196 100644 --- a/Masonry/ViewController+MASAdditions.h +++ b/Masonry/ViewController+MASAdditions.h @@ -1,5 +1,5 @@ // -// UIViewController+MASAdditions.h +// ViewController+MASAdditions.h // Masonry // // Created by Craig Siemens on 2015-06-23. @@ -17,12 +17,12 @@ /** * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute */ -@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide NS_DEPRECATED_IOS(8.0, 11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide NS_DEPRECATED_IOS(8.0, 11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop NS_DEPRECATED_IOS(8.0, 11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom NS_DEPRECATED_IOS(8.0, 11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop NS_DEPRECATED_IOS(8.0, 11.0); -@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom NS_DEPRECATED_IOS(8.0, 11.0); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide API_DEPRECATED("Use view.mas_safeAreaLayoutGuideTop instead of mas_topLayoutGuide", ios(8.0, 11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide API_DEPRECATED("Use view.mas_safeAreaLayoutGuideBottom instead of mas_bottomLayoutGuide", ios(8.0, 11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop API_DEPRECATED("Use view.mas_top instead of mas_topLayoutGuideTop", ios(8.0, 11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom API_DEPRECATED("Use view.mas_safeAreaLayoutGuideTop instead of mas_topLayoutGuideBottom", ios(8.0, 11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop API_DEPRECATED("Use view.mas_safeAreaLayoutGuideBottom instead of mas_bottomLayoutGuideTop", ios(8.0, 11.0)); +@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom API_DEPRECATED("Use view.mas_bottom instead of mas_bottomLayoutGuideBottom", ios(8.0, 11.0)); @end diff --git a/Masonry/ViewController+MASAdditions.m b/Masonry/ViewController+MASAdditions.m index 9d8d378c..6ff24e09 100644 --- a/Masonry/ViewController+MASAdditions.m +++ b/Masonry/ViewController+MASAdditions.m @@ -1,5 +1,5 @@ // -// UIViewController+MASAdditions.m +// ViewController+MASAdditions.m // Masonry // // Created by Craig Siemens on 2015-06-23. diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..e35135dd --- /dev/null +++ b/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. +import PackageDescription + +let package = Package( + name: "Masonry", + platforms: [ + .macOS(.v10_11), + .iOS(.v9), + .tvOS(.v9) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "Masonry", + targets: ["Masonry"]) + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "Masonry", + path: ".", + exclude: ["Masonry/Info.plist"], + sources: ["Masonry"], + publicHeadersPath: "Masonry" + ) + ] +) diff --git a/Tests/Specs/NSLayoutConstraint+MASDebugAdditionsSpec.m b/Tests/Specs/NSLayoutConstraint+MASDebugAdditionsSpec.m index a9d4061a..11b1d218 100644 --- a/Tests/Specs/NSLayoutConstraint+MASDebugAdditionsSpec.m +++ b/Tests/Specs/NSLayoutConstraint+MASDebugAdditionsSpec.m @@ -35,7 +35,7 @@ - (void)testDisplayLayoutConstraintKey { MASLayoutConstraint *layoutConstraint = [MASLayoutConstraint constraintWithItem:newView1 attribute:NSLayoutAttributeBaseline relatedBy:NSLayoutRelationEqual toItem:newView2 attribute:NSLayoutAttributeTop multiplier:2 constant:300]; layoutConstraint.mas_key = @"helloConstraint"; - NSString *description = [NSString stringWithFormat:@"", MAS_VIEW.class, MAS_VIEW.class]; + NSString *description = [NSString stringWithFormat:@"", MAS_VIEW.class, MAS_VIEW.class]; expect([layoutConstraint description]).to.equal(description); } @@ -57,4 +57,4 @@ - (void)testDisplayConstraintKey { expect([superview.constraints[0] description]).to.equal(description); } -SpecEnd \ No newline at end of file +SpecEnd