├── Example-iOS
├── Assets.xcassets
│ ├── Contents.json
│ ├── AccentColor.colorset
│ │ └── Contents.json
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── AppDelegate.swift
├── Info.plist
├── ListViewController.swift
├── Base.lproj
│ └── LaunchScreen.storyboard
├── demos
│ ├── SimpleLayoutViewController.swift
│ └── BasicUIScrollViewController.swift
└── Example-iOS.xcodeproj
│ └── project.pbxproj
├── .gitignore
├── SnapKitPlayground.playground
├── playground.xcworkspace
│ └── contents.xcworkspacedata
├── timeline.xctimeline
├── contents.xcplayground
└── Contents.swift
├── SnapKit.xcworkspace
├── xcshareddata
│ ├── IDEWorkspaceChecks.plist
│ └── SnapKit.xccheckout
└── contents.xcworkspacedata
├── .travis.yml
├── Sources
├── PrivacyInfo.xcprivacy
├── ConstraintView.swift
├── ConstraintInsets.swift
├── ConstraintDirectionalInsets.swift
├── UILayoutSupport+Extensions.swift
├── ConstraintLayoutSupport.swift
├── ConstraintLayoutGuide+Extensions.swift
├── ConstraintLayoutGuide.swift
├── ConstraintConfig.swift
├── ConstraintRelation.swift
├── Typealiases.swift
├── ConstraintMakerFinalizable.swift
├── ConstraintDirectionalInsetTarget.swift
├── ConstraintLayoutSupportDSL.swift
├── ConstraintItem.swift
├── ConstraintRelatableTarget.swift
├── ConstraintMultiplierTarget.swift
├── ConstraintOffsetTarget.swift
├── LayoutConstraint.swift
├── ConstraintPriorityTarget.swift
├── ConstraintLayoutGuideDSL.swift
├── ConstraintMakerEditable.swift
├── ConstraintPriority.swift
├── ConstraintDescription.swift
├── ConstraintMakerPrioritizable.swift
├── ConstraintMakerRelatable+Extensions.swift
├── ConstraintInsetTarget.swift
├── LayoutConstraintItem.swift
├── ConstraintViewDSL.swift
├── ConstraintMakerRelatable.swift
├── ConstraintView+Extensions.swift
├── ConstraintMakerExtendable.swift
├── Debugging.swift
├── ConstraintDSL.swift
├── ConstraintConstantTarget.swift
├── ConstraintMaker.swift
├── ConstraintAttributes.swift
└── Constraint.swift
├── ISSUE_TEMPLATE.md
├── Tests
└── SnapKitTests
│ └── Info.plist
├── Documentation
└── SnapKit 3.0 Migration Guide.md
├── SnapKit.podspec
├── CodeSnippets
├── SnapKit Constraint Make.codesnippet
└── SnapKit Constraint Remake.codesnippet
├── Supporting Files
└── Info.plist
├── LICENSE
├── CONTRIBUTING.md
├── Package.swift
├── SnapKit.xcodeproj
└── xcshareddata
│ └── xcschemes
│ └── SnapKit.xcscheme
└── README.md
/Example-iOS/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .build/
2 | project.xcworkspace
3 | xcuserdata
4 | Examples/
5 | .DS_Store
6 | Gemfile
7 | Gemfile.lock
8 | *.sketch
9 | .swiftpm
10 |
--------------------------------------------------------------------------------
/SnapKitPlayground.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/SnapKitPlayground.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Example-iOS/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SnapKitPlayground.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SnapKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SnapKit.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 | osx_image: xcode11
3 |
4 | env:
5 | - ACTION=test PLATFORM=Mac DESTINATION='platform=macOS'
6 | - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 8'
7 | - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 4K (at 1080p)'
8 |
9 | script:
10 | - set -o pipefail && xcodebuild -scheme SnapKit -destination "$DESTINATION" $ACTION | xcpretty
11 |
--------------------------------------------------------------------------------
/Sources/PrivacyInfo.xcprivacy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrivacyTracking
6 |
7 | NSPrivacyAccessedAPITypes
8 |
9 | NSPrivacyCollectedDataTypes
10 |
11 | NSPrivacyTrackingDomains
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### New Issue Checklist
2 |
3 | 🚫 If this template is not filled out your issue **will** be closed with no comment. 🚫
4 |
5 | * [ ] I have looked at the [Documentation](http://snapkit.io/docs)
6 | * [ ] I have read the [F.A.Q.](http://snapkit.io/faq)
7 | * [ ] I have filled out this issue template.
8 |
9 | ### Issue Info
10 |
11 | Info | Value |
12 | -------------------------|-------------------------------------|
13 | Platform | e.g. ios/osx/tvos
14 | Platform Version | e.g. 8.0
15 | SnapKit Version | e.g. 0.19.0
16 | Integration Method | e.g. carthage/cocoapods/manually
17 |
18 |
19 | ### Issue Description
20 |
21 | ⚠️ Replace this with the description of your issue. ⚠️
22 |
--------------------------------------------------------------------------------
/Tests/SnapKitTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Documentation/SnapKit 3.0 Migration Guide.md:
--------------------------------------------------------------------------------
1 | ## SnapKit 3.0 Migration Guide
2 |
3 | SnapKit 3.0 has many breaking changes from earlier versions. You can read the [notes on releases](https://github.com/SnapKit/SnapKit/releases) for more details.
4 |
5 | 1. Upgrade SnapKit installation
6 | 2. Find all `snp_` and replace with `snp.`
7 | 3. Find all `equalTo(UIEdgeInsets)` and ensure any right or bottom inset values are no longer inverted
8 | 4. Build and fix deprecated APIs
9 | 5. Test every screen of UI to ensure visual compatibility
10 |
11 | If you find any issues with migration please open an issue.
12 |
13 | ### Known Quirks
14 |
15 | 1. `make.center.equalTo(0)` now positions a view at 0,0 in it's superview rather than the center, use `make.center.equalToSuperview` instead.
16 | 2. `updateConstraints` will throw a fatal error if it generates a *new* constraint that did not exist before. Instead use `makeConstraints` to add additional constraints.
--------------------------------------------------------------------------------
/SnapKit.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'SnapKit'
3 | s.version = '5.7.1'
4 | s.license = 'MIT'
5 | s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.'
6 | s.homepage = 'https://github.com/SnapKit/SnapKit'
7 | s.authors = { 'Robert Payne' => 'robertpayne@me.com' }
8 | s.social_media_url = 'http://twitter.com/robertjpayne'
9 | s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '5.7.1' }
10 |
11 | s.ios.deployment_target = '12.0'
12 | s.osx.deployment_target = '10.13'
13 | s.tvos.deployment_target = '12.0'
14 |
15 | s.source_files = 'Sources/*.swift'
16 |
17 | s.libraries = 'swiftCoreGraphics'
18 |
19 | s.xcconfig = {
20 | 'LIBRARY_SEARCH_PATHS' => '$(SDKROOT)/usr/lib/swift',
21 | }
22 |
23 | s.resource_bundles = {
24 | 'SnapKit_Privacy' => ['Sources/PrivacyInfo.xcprivacy'],
25 | }
26 |
27 | s.swift_versions = ['5.0']
28 | end
29 |
--------------------------------------------------------------------------------
/CodeSnippets/SnapKit Constraint Make.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | snpmake
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | <#view#>.snp.makeConstraints { make in
13 | <#code#>
14 | }
15 | IDECodeSnippetIdentifier
16 | FF434629-7B96-4AB9-BD96-522275E7B106
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetTitle
20 | SnapKit Constraint Make
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/CodeSnippets/SnapKit Constraint Remake.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | snpremake
7 | IDECodeSnippetCompletionScopes
8 |
9 | TopLevel
10 |
11 | IDECodeSnippetContents
12 | <#view#>.snp.remakeConstraints { make in
13 | <#code#>
14 | }
15 | IDECodeSnippetIdentifier
16 | FD093546-D614-4311-82C3-E8FE842F62B1
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetTitle
20 | SnapKit Constraint Remake
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Supporting Files/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(CURRENT_PROJECT_VERSION)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Example-iOS/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Example-iOS
4 | //
5 | // Created by Spiros Gerokostas on 01/03/16.
6 | // Copyright © 2016 SnapKit Team. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17 |
18 | self.window = UIWindow()
19 |
20 | let listViewController:ListViewController = ListViewController()
21 | let navigationController:UINavigationController = UINavigationController(rootViewController: listViewController);
22 |
23 | self.window!.rootViewController = navigationController;
24 |
25 | self.window!.backgroundColor = UIColor.white
26 | self.window!.makeKeyAndVisible()
27 |
28 | return true
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/SnapKitPlayground.playground/Contents.swift:
--------------------------------------------------------------------------------
1 | //: A UIKit based Playground for presenting user interface
2 | // To use this playground, build SnapKit.framework for any simulator first.
3 |
4 | import SnapKit
5 | import UIKit
6 | import PlaygroundSupport
7 |
8 | class MyViewController : UIViewController {
9 | override func loadView() {
10 | let view = UIView()
11 | view.backgroundColor = .white
12 |
13 | let label = UILabel()
14 | label.text = "Hello World!"
15 | label.textColor = .black
16 |
17 | view.addSubview(label)
18 |
19 | label.snp.makeConstraints { (make) in
20 | make.left.equalToSuperview().offset(150)
21 | make.top.equalToSuperview().offset(200)
22 | make.size.equalTo(CGSize(width: 200, height: 20))
23 | }
24 |
25 | self.view = view
26 | }
27 | }
28 | // Present the view controller in the Live View window
29 | PlaygroundPage.current.liveView = MyViewController()
30 |
--------------------------------------------------------------------------------
/Example-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "scale" : "1x",
46 | "size" : "1024x1024"
47 | }
48 | ],
49 | "info" : {
50 | "author" : "xcode",
51 | "version" : 1
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | - If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/snapkit). (Tag 'snapkit')
4 | - If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/snapkit).
5 | - If you **found a bug**, open an issue.
6 | - If you **have a feature request**, open an issue.
7 | - If you **want to contribute**, submit a pull request.
8 |
9 | ### Pull Requests
10 |
11 | We gladly accept any PR's assuming they are well written, documented ( if necessary ) and preferably have test code. If you're unsure if we'll accept a new feature please open an issue requesting it and we can have a discussion before you code and submit a PR.
12 |
13 | ### Issues
14 |
15 | Please use the issue tracker *strictly* for bugs you think are caused by a code issue in SnapKit. We’re very busy and as a free open source library do not have the time to adequately help with questions that are more tutorial/training in nature and recommend using Stack Overflow and Google as alternatives.
16 |
17 | Please do not be offended if we close your issue and reference this document. If you believe the issue is truly a fault in SnapKit’s codebase, re-open it.
18 |
--------------------------------------------------------------------------------
/Example-iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Sources/ConstraintView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if canImport(UIKit)
32 | public typealias ConstraintView = UIView
33 | #else
34 | public typealias ConstraintView = NSView
35 | #endif
36 |
--------------------------------------------------------------------------------
/Sources/ConstraintInsets.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if canImport(UIKit)
32 | public typealias ConstraintInsets = UIEdgeInsets
33 | #else
34 | public typealias ConstraintInsets = NSEdgeInsets
35 | #endif
36 |
--------------------------------------------------------------------------------
/Sources/ConstraintDirectionalInsets.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if canImport(UIKit)
32 | @available(iOS 11.0, tvOS 11.0, *)
33 | public typealias ConstraintDirectionalInsets = NSDirectionalEdgeInsets
34 | #endif
35 |
--------------------------------------------------------------------------------
/Sources/UILayoutSupport+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #endif
27 |
28 |
29 | @available(iOS 8.0, *)
30 | public extension ConstraintLayoutSupport {
31 |
32 | var snp: ConstraintLayoutSupportDSL {
33 | return ConstraintLayoutSupportDSL(support: self)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Sources/ConstraintLayoutSupport.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if canImport(UIKit)
32 | @available(iOS 8.0, *)
33 | public typealias ConstraintLayoutSupport = UILayoutSupport
34 | #else
35 | public class ConstraintLayoutSupport {}
36 | #endif
37 |
--------------------------------------------------------------------------------
/Sources/ConstraintLayoutGuide+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #endif
27 |
28 |
29 | @available(iOS 9.0, OSX 10.11, *)
30 | public extension ConstraintLayoutGuide {
31 |
32 | var snp: ConstraintLayoutGuideDSL {
33 | return ConstraintLayoutGuideDSL(guide: self)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Sources/ConstraintLayoutGuide.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if canImport(UIKit)
32 | @available(iOS 9.0, *)
33 | public typealias ConstraintLayoutGuide = UILayoutGuide
34 | #else
35 | @available(OSX 10.11, *)
36 | public typealias ConstraintLayoutGuide = NSLayoutGuide
37 | #endif
38 |
--------------------------------------------------------------------------------
/SnapKit.xcworkspace/xcshareddata/SnapKit.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | A9120727-7306-4189-ADAA-9CB826A3713C
9 | IDESourceControlProjectName
10 | SnapKit
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 3AF18F9C6F5D633BAA0B3F935459E0C777C82047
14 | github.com:Masonry/Snap.git
15 |
16 | IDESourceControlProjectPath
17 | SnapKit.xcworkspace
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 3AF18F9C6F5D633BAA0B3F935459E0C777C82047
21 | ..
22 |
23 | IDESourceControlProjectURL
24 | github.com:Masonry/Snap.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | 3AF18F9C6F5D633BAA0B3F935459E0C777C82047
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 3AF18F9C6F5D633BAA0B3F935459E0C777C82047
36 | IDESourceControlWCCName
37 | SnapKit
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Example-iOS/ListViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // Example-iOS
4 | //
5 | // Created by Spiros Gerokostas on 01/03/16.
6 | // Copyright © 2016 SnapKit Team. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import SnapKit
11 |
12 | class ListViewController: UITableViewController {
13 |
14 | let kCellIdentifier = "CellIdentifier"
15 | let demos = ["Simple Layout", "Basic UIScrollView"]
16 |
17 | override func viewDidLoad() {
18 | super.viewDidLoad()
19 |
20 | self.title = "SnapKit iOS Demos"
21 |
22 | self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
23 | }
24 |
25 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
26 | return demos.count
27 | }
28 |
29 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
30 | let cell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier)! as UITableViewCell
31 |
32 | cell.textLabel?.text = demos[indexPath.row]
33 |
34 | return cell
35 | }
36 |
37 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
38 | if indexPath.row == 0 {
39 | let viewController = SimpleLayoutViewController()
40 | navigationController?.pushViewController(viewController, animated: true)
41 | } else if indexPath.row == 1 {
42 | let viewController = BasicUIScrollViewController()
43 | navigationController?.pushViewController(viewController, animated: true)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Sources/ConstraintConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | public typealias ConstraintInterfaceLayoutDirection = UIUserInterfaceLayoutDirection
27 | #else
28 | import AppKit
29 | public typealias ConstraintInterfaceLayoutDirection = NSUserInterfaceLayoutDirection
30 | #endif
31 |
32 |
33 | public struct ConstraintConfig {
34 |
35 | public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .leftToRight
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Example-iOS/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sources/ConstraintRelation.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | internal enum ConstraintRelation : Int {
32 | case equal = 1
33 | case lessThanOrEqual
34 | case greaterThanOrEqual
35 |
36 | internal var layoutRelation: LayoutRelation {
37 | get {
38 | switch(self) {
39 | case .equal:
40 | return .equal
41 | case .lessThanOrEqual:
42 | return .lessThanOrEqual
43 | case .greaterThanOrEqual:
44 | return .greaterThanOrEqual
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Sources/Typealiases.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | import Foundation
25 |
26 | #if canImport(UIKit)
27 | import UIKit
28 | #if swift(>=4.2)
29 | typealias LayoutRelation = NSLayoutConstraint.Relation
30 | typealias LayoutAttribute = NSLayoutConstraint.Attribute
31 | #else
32 | typealias LayoutRelation = NSLayoutRelation
33 | typealias LayoutAttribute = NSLayoutAttribute
34 | #endif
35 | typealias LayoutPriority = UILayoutPriority
36 | #else
37 | import AppKit
38 | typealias LayoutRelation = NSLayoutConstraint.Relation
39 | typealias LayoutAttribute = NSLayoutConstraint.Attribute
40 | typealias LayoutPriority = NSLayoutConstraint.Priority
41 | #endif
42 |
43 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.8
2 | //
3 | // SnapKit
4 | //
5 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 |
26 | import PackageDescription
27 |
28 | let package = Package(
29 | name: "SnapKit",
30 | platforms: [
31 | .iOS(.v12),
32 | .macOS(.v10_13),
33 | .tvOS(.v12)
34 | ],
35 | products: [
36 | .library(name: "SnapKit", targets: ["SnapKit"]),
37 | .library(name: "SnapKit-Dynamic", type: .dynamic, targets: ["SnapKit"]),
38 | ],
39 | targets: [
40 | .target(name: "SnapKit", path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]),
41 | .testTarget(name: "SnapKitTests", dependencies: ["SnapKit"]),
42 | ],
43 | swiftLanguageVersions: [
44 | .v5
45 | ]
46 | )
47 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerFinalizable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerFinalizable {
32 |
33 | internal let description: ConstraintDescription
34 |
35 | internal init(_ description: ConstraintDescription) {
36 | self.description = description
37 | }
38 |
39 | @discardableResult
40 | public func labeled(_ label: String) -> ConstraintMakerFinalizable {
41 | self.description.label = label
42 | return self
43 | }
44 |
45 | public var constraint: Constraint {
46 | return self.description.constraint!
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Sources/ConstraintDirectionalInsetTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | #if canImport(UIKit)
31 | public protocol ConstraintDirectionalInsetTarget: ConstraintConstantTarget {
32 | }
33 |
34 | @available(iOS 11.0, tvOS 11.0, *)
35 | extension ConstraintDirectionalInsets: ConstraintDirectionalInsetTarget {
36 | }
37 |
38 | extension ConstraintDirectionalInsetTarget {
39 |
40 | @available(iOS 11.0, tvOS 11.0, *)
41 | internal var constraintDirectionalInsetTargetValue: ConstraintDirectionalInsets {
42 | if let amount = self as? ConstraintDirectionalInsets {
43 | return amount
44 | } else {
45 | return ConstraintDirectionalInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
46 | }
47 | }
48 | }
49 | #endif
50 |
--------------------------------------------------------------------------------
/Sources/ConstraintLayoutSupportDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | @available(iOS 8.0, *)
32 | public struct ConstraintLayoutSupportDSL: ConstraintDSL {
33 |
34 | public var target: AnyObject? {
35 | return self.support
36 | }
37 |
38 | internal let support: ConstraintLayoutSupport
39 |
40 | internal init(support: ConstraintLayoutSupport) {
41 | self.support = support
42 |
43 | }
44 |
45 | public var top: ConstraintItem {
46 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top)
47 | }
48 |
49 | public var bottom: ConstraintItem {
50 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom)
51 | }
52 |
53 | public var height: ConstraintItem {
54 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Sources/ConstraintItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public final class ConstraintItem {
32 |
33 | internal weak var target: AnyObject?
34 | internal let attributes: ConstraintAttributes
35 |
36 | internal init(target: AnyObject?, attributes: ConstraintAttributes) {
37 | self.target = target
38 | self.attributes = attributes
39 | }
40 |
41 | internal var layoutConstraintItem: LayoutConstraintItem? {
42 | return self.target as? LayoutConstraintItem
43 | }
44 |
45 | }
46 |
47 | public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool {
48 | // pointer equality
49 | guard lhs !== rhs else {
50 | return true
51 | }
52 |
53 | // must both have valid targets and identical attributes
54 | guard let target1 = lhs.target,
55 | let target2 = rhs.target,
56 | target1 === target2 && lhs.attributes == rhs.attributes else {
57 | return false
58 | }
59 |
60 | return true
61 | }
62 |
--------------------------------------------------------------------------------
/Sources/ConstraintRelatableTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintRelatableTarget {
32 | }
33 |
34 | extension Int: ConstraintRelatableTarget {
35 | }
36 |
37 | extension UInt: ConstraintRelatableTarget {
38 | }
39 |
40 | extension Float: ConstraintRelatableTarget {
41 | }
42 |
43 | extension Double: ConstraintRelatableTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintRelatableTarget {
47 | }
48 |
49 | extension CGSize: ConstraintRelatableTarget {
50 | }
51 |
52 | extension CGPoint: ConstraintRelatableTarget {
53 | }
54 |
55 | extension ConstraintInsets: ConstraintRelatableTarget {
56 | }
57 |
58 | #if canImport(UIKit)
59 | @available(iOS 11.0, tvOS 11.0, *)
60 | extension ConstraintDirectionalInsets: ConstraintRelatableTarget {
61 | }
62 | #endif
63 |
64 | extension ConstraintItem: ConstraintRelatableTarget {
65 | }
66 |
67 | extension ConstraintView: ConstraintRelatableTarget {
68 | }
69 |
70 | @available(iOS 9.0, OSX 10.11, *)
71 | extension ConstraintLayoutGuide: ConstraintRelatableTarget {
72 | }
73 |
--------------------------------------------------------------------------------
/Sources/ConstraintMultiplierTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintMultiplierTarget {
32 |
33 | var constraintMultiplierTargetValue: CGFloat { get }
34 |
35 | }
36 |
37 | extension Int: ConstraintMultiplierTarget {
38 |
39 | public var constraintMultiplierTargetValue: CGFloat {
40 | return CGFloat(self)
41 | }
42 |
43 | }
44 |
45 | extension UInt: ConstraintMultiplierTarget {
46 |
47 | public var constraintMultiplierTargetValue: CGFloat {
48 | return CGFloat(self)
49 | }
50 |
51 | }
52 |
53 | extension Float: ConstraintMultiplierTarget {
54 |
55 | public var constraintMultiplierTargetValue: CGFloat {
56 | return CGFloat(self)
57 | }
58 |
59 | }
60 |
61 | extension Double: ConstraintMultiplierTarget {
62 |
63 | public var constraintMultiplierTargetValue: CGFloat {
64 | return CGFloat(self)
65 | }
66 |
67 | }
68 |
69 | extension CGFloat: ConstraintMultiplierTarget {
70 |
71 | public var constraintMultiplierTargetValue: CGFloat {
72 | return self
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/Sources/ConstraintOffsetTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintOffsetTarget: ConstraintConstantTarget {
32 | }
33 |
34 | extension Int: ConstraintOffsetTarget {
35 | }
36 |
37 | extension UInt: ConstraintOffsetTarget {
38 | }
39 |
40 | extension Float: ConstraintOffsetTarget {
41 | }
42 |
43 | extension Double: ConstraintOffsetTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintOffsetTarget {
47 | }
48 |
49 | extension ConstraintOffsetTarget {
50 |
51 | internal var constraintOffsetTargetValue: CGFloat {
52 | let offset: CGFloat
53 | if let amount = self as? Float {
54 | offset = CGFloat(amount)
55 | } else if let amount = self as? Double {
56 | offset = CGFloat(amount)
57 | } else if let amount = self as? CGFloat {
58 | offset = CGFloat(amount)
59 | } else if let amount = self as? Int {
60 | offset = CGFloat(amount)
61 | } else if let amount = self as? UInt {
62 | offset = CGFloat(amount)
63 | } else {
64 | offset = 0.0
65 | }
66 | return offset
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/Sources/LayoutConstraint.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class LayoutConstraint : NSLayoutConstraint {
32 |
33 | public var label: String? {
34 | get {
35 | return self.identifier
36 | }
37 | set {
38 | self.identifier = newValue
39 | }
40 | }
41 |
42 | internal weak var constraint: Constraint? = nil
43 |
44 | }
45 |
46 | internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool {
47 | // If firstItem or secondItem on either constraint has a dangling pointer
48 | // this comparison can cause a crash. The solution for this is to ensure
49 | // your layout code hold strong references to things like Views, LayoutGuides
50 | // and LayoutAnchors as SnapKit will not keep strong references to any of these.
51 | guard lhs.firstAttribute == rhs.firstAttribute &&
52 | lhs.secondAttribute == rhs.secondAttribute &&
53 | lhs.relation == rhs.relation &&
54 | lhs.priority == rhs.priority &&
55 | lhs.multiplier == rhs.multiplier &&
56 | lhs.secondItem === rhs.secondItem &&
57 | lhs.firstItem === rhs.firstItem else {
58 | return false
59 | }
60 | return true
61 | }
62 |
--------------------------------------------------------------------------------
/Sources/ConstraintPriorityTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintPriorityTarget {
32 |
33 | var constraintPriorityTargetValue: Float { get }
34 |
35 | }
36 |
37 | extension Int: ConstraintPriorityTarget {
38 |
39 | public var constraintPriorityTargetValue: Float {
40 | return Float(self)
41 | }
42 |
43 | }
44 |
45 | extension UInt: ConstraintPriorityTarget {
46 |
47 | public var constraintPriorityTargetValue: Float {
48 | return Float(self)
49 | }
50 |
51 | }
52 |
53 | extension Float: ConstraintPriorityTarget {
54 |
55 | public var constraintPriorityTargetValue: Float {
56 | return self
57 | }
58 |
59 | }
60 |
61 | extension Double: ConstraintPriorityTarget {
62 |
63 | public var constraintPriorityTargetValue: Float {
64 | return Float(self)
65 | }
66 |
67 | }
68 |
69 | extension CGFloat: ConstraintPriorityTarget {
70 |
71 | public var constraintPriorityTargetValue: Float {
72 | return Float(self)
73 | }
74 |
75 | }
76 |
77 | #if canImport(UIKit)
78 | extension UILayoutPriority: ConstraintPriorityTarget {
79 |
80 | public var constraintPriorityTargetValue: Float {
81 | return self.rawValue
82 | }
83 |
84 | }
85 | #endif
86 |
--------------------------------------------------------------------------------
/Sources/ConstraintLayoutGuideDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | @available(iOS 9.0, OSX 10.11, *)
32 | public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL {
33 |
34 | @discardableResult
35 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
36 | return ConstraintMaker.prepareConstraints(item: self.guide, closure: closure)
37 | }
38 |
39 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
40 | ConstraintMaker.makeConstraints(item: self.guide, closure: closure)
41 | }
42 |
43 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
44 | ConstraintMaker.remakeConstraints(item: self.guide, closure: closure)
45 | }
46 |
47 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
48 | ConstraintMaker.updateConstraints(item: self.guide, closure: closure)
49 | }
50 |
51 | public func removeConstraints() {
52 | ConstraintMaker.removeConstraints(item: self.guide)
53 | }
54 |
55 | public var target: AnyObject? {
56 | return self.guide
57 | }
58 |
59 | internal let guide: ConstraintLayoutGuide
60 |
61 | internal init(guide: ConstraintLayoutGuide) {
62 | self.guide = guide
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerEditable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerEditable: ConstraintMakerPrioritizable {
32 |
33 | @discardableResult
34 | public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
35 | self.description.multiplier = amount
36 | return self
37 | }
38 |
39 | @discardableResult
40 | public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
41 | return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue)
42 | }
43 |
44 | @discardableResult
45 | public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable {
46 | self.description.constant = amount.constraintOffsetTargetValue
47 | return self
48 | }
49 |
50 | @discardableResult
51 | public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable {
52 | self.description.constant = amount.constraintInsetTargetValue
53 | return self
54 | }
55 |
56 | #if canImport(UIKit)
57 | @discardableResult
58 | @available(iOS 11.0, tvOS 11.0, *)
59 | public func inset(_ amount: ConstraintDirectionalInsetTarget) -> ConstraintMakerEditable {
60 | self.description.constant = amount.constraintDirectionalInsetTargetValue
61 | return self
62 | }
63 | #endif
64 | }
65 |
--------------------------------------------------------------------------------
/Sources/ConstraintPriority.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable {
31 | public typealias FloatLiteralType = Float
32 |
33 | public let value: Float
34 |
35 | public init(floatLiteral value: Float) {
36 | self.value = value
37 | }
38 |
39 | public init(_ value: Float) {
40 | self.value = value
41 | }
42 |
43 | public static var required: ConstraintPriority {
44 | return 1000.0
45 | }
46 |
47 | public static var high: ConstraintPriority {
48 | return 750.0
49 | }
50 |
51 | public static var medium: ConstraintPriority {
52 | #if os(OSX)
53 | return 501.0
54 | #else
55 | return 500.0
56 | #endif
57 |
58 | }
59 |
60 | public static var low: ConstraintPriority {
61 | return 250.0
62 | }
63 |
64 | public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
65 | return lhs.value == rhs.value
66 | }
67 |
68 | // MARK: Strideable
69 |
70 | public func advanced(by n: FloatLiteralType) -> ConstraintPriority {
71 | return ConstraintPriority(floatLiteral: value + n)
72 | }
73 |
74 | public func distance(to other: ConstraintPriority) -> FloatLiteralType {
75 | return other.value - value
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Sources/ConstraintDescription.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintDescription {
32 |
33 | internal let item: LayoutConstraintItem
34 | internal var attributes: ConstraintAttributes
35 | internal var relation: ConstraintRelation? = nil
36 | internal var sourceLocation: (String, UInt)? = nil
37 | internal var label: String? = nil
38 | internal var related: ConstraintItem? = nil
39 | internal var multiplier: ConstraintMultiplierTarget = 1.0
40 | internal var constant: ConstraintConstantTarget = 0.0
41 | internal var priority: ConstraintPriorityTarget = 1000.0
42 | internal lazy var constraint: Constraint? = {
43 | guard let relation = self.relation,
44 | let related = self.related,
45 | let sourceLocation = self.sourceLocation else {
46 | return nil
47 | }
48 | let from = ConstraintItem(target: self.item, attributes: self.attributes)
49 |
50 | return Constraint(
51 | from: from,
52 | to: related,
53 | relation: relation,
54 | sourceLocation: sourceLocation,
55 | label: self.label,
56 | multiplier: self.multiplier,
57 | constant: self.constant,
58 | priority: self.priority
59 | )
60 | }()
61 |
62 | // MARK: Initialization
63 |
64 | internal init(item: LayoutConstraintItem, attributes: ConstraintAttributes) {
65 | self.item = item
66 | self.attributes = attributes
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerPrioritizable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | @available(*, deprecated, message:"Use ConstraintMakerPrioritizable instead.")
31 | public typealias ConstraintMakerPriortizable = ConstraintMakerPrioritizable
32 |
33 | public class ConstraintMakerPrioritizable: ConstraintMakerFinalizable {
34 |
35 | @discardableResult
36 | public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable {
37 | self.description.priority = amount.value
38 | return self
39 | }
40 |
41 | @discardableResult
42 | public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable {
43 | self.description.priority = amount
44 | return self
45 | }
46 |
47 | @available(*, deprecated, message:"Use priority(.required) instead.")
48 | @discardableResult
49 | public func priorityRequired() -> ConstraintMakerFinalizable {
50 | return self.priority(.required)
51 | }
52 |
53 | @available(*, deprecated, message:"Use priority(.high) instead.")
54 | @discardableResult
55 | public func priorityHigh() -> ConstraintMakerFinalizable {
56 | return self.priority(.high)
57 | }
58 |
59 | @available(*, deprecated, message:"Use priority(.medium) instead.")
60 | @discardableResult
61 | public func priorityMedium() -> ConstraintMakerFinalizable {
62 | return self.priority(.medium)
63 | }
64 |
65 | @available(*, deprecated, message:"Use priority(.low) instead.")
66 | @discardableResult
67 | public func priorityLow() -> ConstraintMakerFinalizable {
68 | return self.priority(.low)
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerRelatable+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | extension ConstraintMakerRelatable {
32 |
33 | @discardableResult
34 | public func equalToSuperview(_ closure: (ConstraintView) -> T, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
35 | guard let other = self.description.item.superview else {
36 | fatalError("Expected superview but found nil when attempting make constraint `equalToSuperview`.")
37 | }
38 | return self.relatedTo(closure(other), relation: .equal, file: file, line: line)
39 | }
40 |
41 | @discardableResult
42 | public func lessThanOrEqualToSuperview(_ closure: (ConstraintView) -> T, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
43 | guard let other = self.description.item.superview else {
44 | fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.")
45 | }
46 | return self.relatedTo(closure(other), relation: .lessThanOrEqual, file: file, line: line)
47 | }
48 |
49 | @discardableResult
50 | public func greaterThanOrEqualToSuperview(_ closure: (ConstraintView) -> T, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
51 | guard let other = self.description.item.superview else {
52 | fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.")
53 | }
54 | return self.relatedTo(closure(other), relation: .greaterThanOrEqual, file: file, line: line)
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/Sources/ConstraintInsetTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintInsetTarget: ConstraintConstantTarget {
32 | }
33 |
34 | extension Int: ConstraintInsetTarget {
35 | }
36 |
37 | extension UInt: ConstraintInsetTarget {
38 | }
39 |
40 | extension Float: ConstraintInsetTarget {
41 | }
42 |
43 | extension Double: ConstraintInsetTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintInsetTarget {
47 | }
48 |
49 | extension ConstraintInsets: ConstraintInsetTarget {
50 | }
51 |
52 | extension ConstraintInsetTarget {
53 |
54 | internal var constraintInsetTargetValue: ConstraintInsets {
55 | if let amount = self as? ConstraintInsets {
56 | return amount
57 | } else if let amount = self as? Float {
58 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
59 | } else if let amount = self as? Double {
60 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
61 | } else if let amount = self as? CGFloat {
62 | return ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount)
63 | } else if let amount = self as? Int {
64 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
65 | } else if let amount = self as? UInt {
66 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
67 | } else {
68 | return ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0)
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/Example-iOS/demos/SimpleLayoutViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SimpleLayoutViewController.swift
3 | // SnapKit
4 | //
5 | // Created by Spiros Gerokostas on 01/03/16.
6 | // Copyright © 2016 SnapKit Team. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class SimpleLayoutViewController: UIViewController {
12 |
13 | var didSetupConstraints = false
14 |
15 | let blackView: UIView = {
16 | let view = UIView()
17 | view.backgroundColor = .black
18 | return view
19 | }()
20 |
21 | let redView: UIView = {
22 | let view = UIView()
23 | view.backgroundColor = .red
24 | return view
25 | }()
26 |
27 | let yellowView: UIView = {
28 | let view = UIView()
29 | view.backgroundColor = .yellow
30 | return view
31 | }()
32 |
33 | let blueView: UIView = {
34 | let view = UIView()
35 | view.backgroundColor = .blue
36 | return view
37 | }()
38 |
39 | let greenView: UIView = {
40 | let view = UIView()
41 | view.backgroundColor = .green
42 | return view
43 | }()
44 |
45 | override func viewDidLoad() {
46 | super.viewDidLoad()
47 |
48 | view.backgroundColor = UIColor.white
49 |
50 | view.addSubview(blackView)
51 | view.addSubview(redView)
52 | view.addSubview(yellowView)
53 | view.addSubview(blueView)
54 | view.addSubview(greenView)
55 |
56 | view.setNeedsUpdateConstraints()
57 | }
58 |
59 | override func updateViewConstraints() {
60 |
61 | if (!didSetupConstraints) {
62 |
63 | blackView.snp.makeConstraints { make in
64 | make.center.equalTo(view)
65 | make.size.equalTo(CGSize(width: 100, height: 100))
66 | }
67 |
68 | redView.snp.makeConstraints { make in
69 | make.top.equalTo(blackView.snp.bottom).offset(20.0)
70 | make.right.equalTo(blackView.snp.left).offset(-20.0)
71 | make.size.equalTo(CGSize(width: 100, height: 100))
72 | }
73 |
74 | yellowView.snp.makeConstraints { make in
75 | make.top.equalTo(blackView.snp.bottom).offset(20.0)
76 | make.left.equalTo(blackView.snp.right).offset(20.0)
77 | make.size.equalTo(CGSize(width: 100, height: 100))
78 | }
79 |
80 | blueView.snp.makeConstraints { make in
81 | make.bottom.equalTo(blackView.snp.top).offset(-20.0)
82 | make.left.equalTo(blackView.snp.right).offset(20.0)
83 | make.size.equalTo(CGSize(width: 100, height: 100))
84 | }
85 |
86 | greenView.snp.makeConstraints { make in
87 | make.bottom.equalTo(blackView.snp.top).offset(-20.0)
88 | make.right.equalTo(blackView.snp.left).offset(-20.0)
89 | make.size.equalTo(CGSize(width: 100, height: 100))
90 | }
91 |
92 | didSetupConstraints = true
93 | }
94 |
95 | super.updateViewConstraints()
96 | }
97 | }
--------------------------------------------------------------------------------
/Sources/LayoutConstraintItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol LayoutConstraintItem: AnyObject {
32 | }
33 |
34 | @available(iOS 9.0, OSX 10.11, *)
35 | extension ConstraintLayoutGuide : LayoutConstraintItem {
36 | }
37 |
38 | extension ConstraintView : LayoutConstraintItem {
39 | }
40 |
41 |
42 | extension LayoutConstraintItem {
43 |
44 | internal func prepare() {
45 | if let view = self as? ConstraintView {
46 | view.translatesAutoresizingMaskIntoConstraints = false
47 | }
48 | }
49 |
50 | internal var superview: ConstraintView? {
51 | if let view = self as? ConstraintView {
52 | return view.superview
53 | }
54 |
55 | if #available(iOS 9.0, OSX 10.11, *), let guide = self as? ConstraintLayoutGuide {
56 | return guide.owningView
57 | }
58 |
59 | return nil
60 | }
61 | internal var constraints: [Constraint] {
62 | return self.constraintsSet.allObjects as! [Constraint]
63 | }
64 |
65 | internal func add(constraints: [Constraint]) {
66 | let constraintsSet = self.constraintsSet
67 | for constraint in constraints {
68 | constraintsSet.add(constraint)
69 | }
70 | }
71 |
72 | internal func remove(constraints: [Constraint]) {
73 | let constraintsSet = self.constraintsSet
74 | for constraint in constraints {
75 | constraintsSet.remove(constraint)
76 | }
77 | }
78 |
79 | private var constraintsSet: NSMutableSet {
80 | let constraintsSet: NSMutableSet
81 |
82 | if let existing = objc_getAssociatedObject(self, &constraintsKey) as? NSMutableSet {
83 | constraintsSet = existing
84 | } else {
85 | constraintsSet = NSMutableSet()
86 | objc_setAssociatedObject(self, &constraintsKey, constraintsSet, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
87 | }
88 | return constraintsSet
89 |
90 | }
91 |
92 | }
93 | private var constraintsKey: UInt8 = 0
94 |
--------------------------------------------------------------------------------
/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
42 |
48 |
49 |
50 |
51 |
52 |
62 |
63 |
69 |
70 |
71 |
72 |
78 |
79 |
85 |
86 |
87 |
88 |
90 |
91 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/Sources/ConstraintViewDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public struct ConstraintViewDSL: ConstraintAttributesDSL {
32 |
33 | @discardableResult
34 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
35 | return ConstraintMaker.prepareConstraints(item: self.view, closure: closure)
36 | }
37 |
38 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
39 | ConstraintMaker.makeConstraints(item: self.view, closure: closure)
40 | }
41 |
42 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
43 | ConstraintMaker.remakeConstraints(item: self.view, closure: closure)
44 | }
45 |
46 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
47 | ConstraintMaker.updateConstraints(item: self.view, closure: closure)
48 | }
49 |
50 | public func removeConstraints() {
51 | ConstraintMaker.removeConstraints(item: self.view)
52 | }
53 |
54 | public var contentHuggingHorizontalPriority: Float {
55 | get {
56 | return self.view.contentHuggingPriority(for: .horizontal).rawValue
57 | }
58 | nonmutating set {
59 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .horizontal)
60 | }
61 | }
62 |
63 | public var contentHuggingVerticalPriority: Float {
64 | get {
65 | return self.view.contentHuggingPriority(for: .vertical).rawValue
66 | }
67 | nonmutating set {
68 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .vertical)
69 | }
70 | }
71 |
72 | public var contentCompressionResistanceHorizontalPriority: Float {
73 | get {
74 | return self.view.contentCompressionResistancePriority(for: .horizontal).rawValue
75 | }
76 | nonmutating set {
77 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .horizontal)
78 | }
79 | }
80 |
81 | public var contentCompressionResistanceVerticalPriority: Float {
82 | get {
83 | return self.view.contentCompressionResistancePriority(for: .vertical).rawValue
84 | }
85 | nonmutating set {
86 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .vertical)
87 | }
88 | }
89 |
90 | public var target: AnyObject? {
91 | return self.view
92 | }
93 |
94 | internal let view: ConstraintView
95 |
96 | internal init(view: ConstraintView) {
97 | self.view = view
98 |
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/Example-iOS/demos/BasicUIScrollViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // BasicUIScrollViewController.swift
3 | // SnapKit
4 | //
5 | // Created by Spiros Gerokostas on 01/03/16.
6 | // Copyright © 2016 SnapKit Team. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class BasicUIScrollViewController: UIViewController {
12 |
13 | var didSetupConstraints = false
14 |
15 | let scrollView = UIScrollView()
16 | let contentView = UIView()
17 |
18 | let label: UILabel = {
19 | let label = UILabel()
20 | label.backgroundColor = .blue
21 | label.numberOfLines = 0
22 | label.lineBreakMode = .byClipping
23 | label.textColor = .white
24 | label.text = NSLocalizedString("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", comment: "")
25 | return label
26 | }()
27 |
28 | override func viewDidLoad() {
29 | super.viewDidLoad()
30 |
31 | view.backgroundColor = UIColor.white
32 |
33 | view.addSubview(scrollView)
34 |
35 | contentView.backgroundColor = UIColor.lightGray
36 | scrollView.addSubview(contentView)
37 | contentView.addSubview(label)
38 |
39 | view.setNeedsUpdateConstraints()
40 | }
41 |
42 | override func updateViewConstraints() {
43 |
44 | if (!didSetupConstraints) {
45 |
46 | scrollView.snp.makeConstraints { make in
47 | make.edges.equalTo(view).inset(UIEdgeInsets.zero)
48 | }
49 |
50 | contentView.snp.makeConstraints { make in
51 | make.edges.equalTo(scrollView).inset(UIEdgeInsets.zero)
52 | make.width.equalTo(scrollView)
53 | }
54 |
55 | label.snp.makeConstraints { make in
56 | make.top.equalTo(contentView).inset(20)
57 | make.leading.equalTo(contentView).inset(20)
58 | make.trailing.equalTo(contentView).inset(20)
59 | make.bottom.equalTo(contentView).inset(20)
60 | }
61 |
62 | didSetupConstraints = true
63 | }
64 |
65 | super.updateViewConstraints()
66 | }
67 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | SnapKit is a DSL to make Auto Layout easy on both iOS and OS X.
4 |
5 | [](https://travis-ci.org/SnapKit/SnapKit)
6 | [](https://github.com/SnapKit/SnapKit)
7 | [](https://cocoapods.org/pods/SnapKit)
8 | [](https://github.com/Carthage/Carthage)
9 |
10 | #### ⚠️ **To use with Swift 4.x please ensure you are using >= 4.0.0** ⚠️
11 | #### ⚠️ **To use with Swift 5.x please ensure you are using >= 5.0.0** ⚠️
12 |
13 | ## Contents
14 |
15 | - [Requirements](#requirements)
16 | - [Migration Guides](#migration-guides)
17 | - [Communication](#communication)
18 | - [Installation](#installation)
19 | - [Usage](#usage)
20 | - [Credits](#credits)
21 | - [License](#license)
22 |
23 | ## Requirements
24 |
25 | - iOS 12.0+ / Mac OS X 10.13+ / tvOS 10.0+
26 | - Xcode 10.0+
27 | - Swift 4.0+
28 |
29 | ## Migration Guides
30 |
31 | - [SnapKit 3.0 Migration Guide](Documentation/SnapKit%203.0%20Migration%20Guide.md)
32 |
33 | ## Communication
34 |
35 | - If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/snapkit). (Tag 'snapkit')
36 | - If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/snapkit).
37 | - If you **found a bug**, open an issue.
38 | - If you **have a feature request**, open an issue.
39 | - If you **want to contribute**, submit a pull request.
40 |
41 |
42 | ## Installation
43 |
44 | ### CocoaPods
45 |
46 | [CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
47 |
48 | ```bash
49 | $ gem install cocoapods
50 | ```
51 |
52 | > CocoaPods 1.1.0+ is required to build SnapKit 4.0.0+.
53 |
54 | To integrate SnapKit into your Xcode project using CocoaPods, specify it in your `Podfile`:
55 |
56 | ```ruby
57 | source 'https://github.com/CocoaPods/Specs.git'
58 | platform :ios, '12.0'
59 | use_frameworks!
60 |
61 | target '' do
62 | pod 'SnapKit', '~> 5.7.0'
63 | end
64 | ```
65 |
66 | Then, run the following command:
67 |
68 | ```bash
69 | $ pod install
70 | ```
71 |
72 | ### Carthage
73 |
74 | [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
75 |
76 | You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
77 |
78 | ```bash
79 | $ brew update
80 | $ brew install carthage
81 | ```
82 |
83 | To integrate SnapKit into your Xcode project using Carthage, specify it in your `Cartfile`:
84 |
85 | ```ogdl
86 | github "SnapKit/SnapKit" ~> 5.0.0
87 | ```
88 |
89 | Run `carthage update` to build the framework and drag the built `SnapKit.framework` into your Xcode project.
90 |
91 | ### Swift Package Manager
92 |
93 | [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
94 |
95 | > Xcode 11+ is required to build SnapKit using Swift Package Manager.
96 |
97 | To integrate SnapKit into your Xcode project using Swift Package Manager, add it to the dependencies value of your `Package.swift`:
98 |
99 | ```swift
100 | dependencies: [
101 | .package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
102 | ]
103 | ```
104 |
105 | ### Manually
106 |
107 | If you prefer not to use either of the aforementioned dependency managers, you can integrate SnapKit into your project manually.
108 |
109 | ---
110 |
111 | ## Usage
112 |
113 | ### Quick Start
114 |
115 | ```swift
116 | import SnapKit
117 |
118 | class MyViewController: UIViewController {
119 |
120 | lazy var box = UIView()
121 |
122 | override func viewDidLoad() {
123 | super.viewDidLoad()
124 |
125 | self.view.addSubview(box)
126 | box.backgroundColor = .green
127 | box.snp.makeConstraints { (make) -> Void in
128 | make.width.height.equalTo(50)
129 | make.center.equalTo(self.view)
130 | }
131 | }
132 |
133 | }
134 | ```
135 |
136 | ### Playground
137 | You can try SnapKit in Playground.
138 |
139 | **Note:**
140 |
141 | > To try SnapKit in playground, open `SnapKit.xcworkspace` and build SnapKit.framework for any simulator first.
142 |
143 | ### Resources
144 |
145 | - [Documentation](https://snapkit.github.io/SnapKit/docs/)
146 | - [F.A.Q.](https://snapkit.github.io/SnapKit/faq/)
147 |
148 | ## Credits
149 |
150 | - Robert Payne ([@robertjpayne](https://twitter.com/robertjpayne))
151 | - Many other contributors
152 |
153 | ## License
154 |
155 | SnapKit is released under the MIT license. See LICENSE for details.
156 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerRelatable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerRelatable {
32 |
33 | internal let description: ConstraintDescription
34 |
35 | internal init(_ description: ConstraintDescription) {
36 | self.description = description
37 | }
38 |
39 | internal func relatedTo(_ other: ConstraintRelatableTarget, relation: ConstraintRelation, file: String, line: UInt) -> ConstraintMakerEditable {
40 | let related: ConstraintItem
41 | let constant: ConstraintConstantTarget
42 |
43 | if let other = other as? ConstraintItem {
44 | guard other.attributes == ConstraintAttributes.none ||
45 | other.attributes.layoutAttributes.count <= 1 ||
46 | other.attributes.layoutAttributes == self.description.attributes.layoutAttributes ||
47 | other.attributes == .edges && self.description.attributes == .margins ||
48 | other.attributes == .margins && self.description.attributes == .edges ||
49 | other.attributes == .directionalEdges && self.description.attributes == .directionalMargins ||
50 | other.attributes == .directionalMargins && self.description.attributes == .directionalEdges else {
51 | fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))");
52 | }
53 |
54 | related = other
55 | constant = 0.0
56 | } else if let other = other as? ConstraintView {
57 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none)
58 | constant = 0.0
59 | } else if let other = other as? ConstraintConstantTarget {
60 | related = ConstraintItem(target: nil, attributes: ConstraintAttributes.none)
61 | constant = other
62 | } else if #available(iOS 9.0, OSX 10.11, *), let other = other as? ConstraintLayoutGuide {
63 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none)
64 | constant = 0.0
65 | } else {
66 | fatalError("Invalid constraint. (\(file), \(line))")
67 | }
68 |
69 | let editable = ConstraintMakerEditable(self.description)
70 | editable.description.sourceLocation = (file, line)
71 | editable.description.relation = relation
72 | editable.description.related = related
73 | editable.description.constant = constant
74 | return editable
75 | }
76 |
77 | @discardableResult
78 | public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
79 | return self.relatedTo(other, relation: .equal, file: file, line: line)
80 | }
81 |
82 | @discardableResult
83 | public func equalToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
84 | guard let other = self.description.item.superview else {
85 | fatalError("Expected superview but found nil when attempting make constraint `equalToSuperview`.")
86 | }
87 | return self.relatedTo(other, relation: .equal, file: file, line: line)
88 | }
89 |
90 | @discardableResult
91 | public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
92 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
93 | }
94 |
95 | @discardableResult
96 | public func lessThanOrEqualToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
97 | guard let other = self.description.item.superview else {
98 | fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.")
99 | }
100 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
101 | }
102 |
103 | @discardableResult
104 | public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
105 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
106 | }
107 |
108 | @discardableResult
109 | public func greaterThanOrEqualToSuperview(_ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
110 | guard let other = self.description.item.superview else {
111 | fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.")
112 | }
113 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/Sources/ConstraintView+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public extension ConstraintView {
32 |
33 | @available(*, deprecated, renamed:"snp.left")
34 | var snp_left: ConstraintItem { return self.snp.left }
35 |
36 | @available(*, deprecated, renamed:"snp.top")
37 | var snp_top: ConstraintItem { return self.snp.top }
38 |
39 | @available(*, deprecated, renamed:"snp.right")
40 | var snp_right: ConstraintItem { return self.snp.right }
41 |
42 | @available(*, deprecated, renamed:"snp.bottom")
43 | var snp_bottom: ConstraintItem { return self.snp.bottom }
44 |
45 | @available(*, deprecated, renamed:"snp.leading")
46 | var snp_leading: ConstraintItem { return self.snp.leading }
47 |
48 | @available(*, deprecated, renamed:"snp.trailing")
49 | var snp_trailing: ConstraintItem { return self.snp.trailing }
50 |
51 | @available(*, deprecated, renamed:"snp.width")
52 | var snp_width: ConstraintItem { return self.snp.width }
53 |
54 | @available(*, deprecated, renamed:"snp.height")
55 | var snp_height: ConstraintItem { return self.snp.height }
56 |
57 | @available(*, deprecated, renamed:"snp.centerX")
58 | var snp_centerX: ConstraintItem { return self.snp.centerX }
59 |
60 | @available(*, deprecated, renamed:"snp.centerY")
61 | var snp_centerY: ConstraintItem { return self.snp.centerY }
62 |
63 | @available(*, deprecated, renamed:"snp.baseline")
64 | var snp_baseline: ConstraintItem { return self.snp.baseline }
65 |
66 | @available(*, deprecated, renamed:"snp.lastBaseline")
67 | @available(iOS 8.0, OSX 10.11, *)
68 | var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline }
69 |
70 | @available(iOS, deprecated, renamed:"snp.firstBaseline")
71 | @available(iOS 8.0, OSX 10.11, *)
72 | var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline }
73 |
74 | @available(iOS, deprecated, renamed:"snp.leftMargin")
75 | @available(iOS 8.0, *)
76 | var snp_leftMargin: ConstraintItem { return self.snp.leftMargin }
77 |
78 | @available(iOS, deprecated, renamed:"snp.topMargin")
79 | @available(iOS 8.0, *)
80 | var snp_topMargin: ConstraintItem { return self.snp.topMargin }
81 |
82 | @available(iOS, deprecated, renamed:"snp.rightMargin")
83 | @available(iOS 8.0, *)
84 | var snp_rightMargin: ConstraintItem { return self.snp.rightMargin }
85 |
86 | @available(iOS, deprecated, renamed:"snp.bottomMargin")
87 | @available(iOS 8.0, *)
88 | var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin }
89 |
90 | @available(iOS, deprecated, renamed:"snp.leadingMargin")
91 | @available(iOS 8.0, *)
92 | var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin }
93 |
94 | @available(iOS, deprecated, renamed:"snp.trailingMargin")
95 | @available(iOS 8.0, *)
96 | var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin }
97 |
98 | @available(iOS, deprecated, renamed:"snp.centerXWithinMargins")
99 | @available(iOS 8.0, *)
100 | var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins }
101 |
102 | @available(iOS, deprecated, renamed:"snp.centerYWithinMargins")
103 | @available(iOS 8.0, *)
104 | var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins }
105 |
106 | @available(*, deprecated, renamed:"snp.edges")
107 | var snp_edges: ConstraintItem { return self.snp.edges }
108 |
109 | @available(*, deprecated, renamed:"snp.size")
110 | var snp_size: ConstraintItem { return self.snp.size }
111 |
112 | @available(*, deprecated, renamed:"snp.center")
113 | var snp_center: ConstraintItem { return self.snp.center }
114 |
115 | @available(iOS, deprecated, renamed:"snp.margins")
116 | @available(iOS 8.0, *)
117 | var snp_margins: ConstraintItem { return self.snp.margins }
118 |
119 | @available(iOS, deprecated, renamed:"snp.centerWithinMargins")
120 | @available(iOS 8.0, *)
121 | var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins }
122 |
123 | @available(*, deprecated, renamed:"snp.prepareConstraints(_:)")
124 | func snp_prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
125 | return self.snp.prepareConstraints(closure)
126 | }
127 |
128 | @available(*, deprecated, renamed:"snp.makeConstraints(_:)")
129 | func snp_makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
130 | self.snp.makeConstraints(closure)
131 | }
132 |
133 | @available(*, deprecated, renamed:"snp.remakeConstraints(_:)")
134 | func snp_remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
135 | self.snp.remakeConstraints(closure)
136 | }
137 |
138 | @available(*, deprecated, renamed:"snp.updateConstraints(_:)")
139 | func snp_updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
140 | self.snp.updateConstraints(closure)
141 | }
142 |
143 | @available(*, deprecated, renamed:"snp.removeConstraints()")
144 | func snp_removeConstraints() {
145 | self.snp.removeConstraints()
146 | }
147 |
148 | var snp: ConstraintViewDSL {
149 | return ConstraintViewDSL(view: self)
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/Sources/ConstraintMakerExtendable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerExtendable: ConstraintMakerRelatable {
32 |
33 | public var left: ConstraintMakerExtendable {
34 | self.description.attributes += .left
35 | return self
36 | }
37 |
38 | public var top: ConstraintMakerExtendable {
39 | self.description.attributes += .top
40 | return self
41 | }
42 |
43 | public var bottom: ConstraintMakerExtendable {
44 | self.description.attributes += .bottom
45 | return self
46 | }
47 |
48 | public var right: ConstraintMakerExtendable {
49 | self.description.attributes += .right
50 | return self
51 | }
52 |
53 | public var leading: ConstraintMakerExtendable {
54 | self.description.attributes += .leading
55 | return self
56 | }
57 |
58 | public var trailing: ConstraintMakerExtendable {
59 | self.description.attributes += .trailing
60 | return self
61 | }
62 |
63 | public var width: ConstraintMakerExtendable {
64 | self.description.attributes += .width
65 | return self
66 | }
67 |
68 | public var height: ConstraintMakerExtendable {
69 | self.description.attributes += .height
70 | return self
71 | }
72 |
73 | public var centerX: ConstraintMakerExtendable {
74 | self.description.attributes += .centerX
75 | return self
76 | }
77 |
78 | public var centerY: ConstraintMakerExtendable {
79 | self.description.attributes += .centerY
80 | return self
81 | }
82 |
83 | @available(*, deprecated, renamed:"lastBaseline")
84 | public var baseline: ConstraintMakerExtendable {
85 | self.description.attributes += .lastBaseline
86 | return self
87 | }
88 |
89 | public var lastBaseline: ConstraintMakerExtendable {
90 | self.description.attributes += .lastBaseline
91 | return self
92 | }
93 |
94 | @available(iOS 8.0, OSX 10.11, *)
95 | public var firstBaseline: ConstraintMakerExtendable {
96 | self.description.attributes += .firstBaseline
97 | return self
98 | }
99 |
100 | @available(iOS 8.0, *)
101 | public var leftMargin: ConstraintMakerExtendable {
102 | self.description.attributes += .leftMargin
103 | return self
104 | }
105 |
106 | @available(iOS 8.0, *)
107 | public var rightMargin: ConstraintMakerExtendable {
108 | self.description.attributes += .rightMargin
109 | return self
110 | }
111 |
112 | @available(iOS 8.0, *)
113 | public var topMargin: ConstraintMakerExtendable {
114 | self.description.attributes += .topMargin
115 | return self
116 | }
117 |
118 | @available(iOS 8.0, *)
119 | public var bottomMargin: ConstraintMakerExtendable {
120 | self.description.attributes += .bottomMargin
121 | return self
122 | }
123 |
124 | @available(iOS 8.0, *)
125 | public var leadingMargin: ConstraintMakerExtendable {
126 | self.description.attributes += .leadingMargin
127 | return self
128 | }
129 |
130 | @available(iOS 8.0, *)
131 | public var trailingMargin: ConstraintMakerExtendable {
132 | self.description.attributes += .trailingMargin
133 | return self
134 | }
135 |
136 | @available(iOS 8.0, *)
137 | public var centerXWithinMargins: ConstraintMakerExtendable {
138 | self.description.attributes += .centerXWithinMargins
139 | return self
140 | }
141 |
142 | @available(iOS 8.0, *)
143 | public var centerYWithinMargins: ConstraintMakerExtendable {
144 | self.description.attributes += .centerYWithinMargins
145 | return self
146 | }
147 |
148 | public var edges: ConstraintMakerExtendable {
149 | self.description.attributes += .edges
150 | return self
151 | }
152 | public var horizontalEdges: ConstraintMakerExtendable {
153 | self.description.attributes += .horizontalEdges
154 | return self
155 | }
156 | public var verticalEdges: ConstraintMakerExtendable {
157 | self.description.attributes += .verticalEdges
158 | return self
159 | }
160 | public var directionalEdges: ConstraintMakerExtendable {
161 | self.description.attributes += .directionalEdges
162 | return self
163 | }
164 | public var directionalHorizontalEdges: ConstraintMakerExtendable {
165 | self.description.attributes += .directionalHorizontalEdges
166 | return self
167 | }
168 | public var directionalVerticalEdges: ConstraintMakerExtendable {
169 | self.description.attributes += .directionalVerticalEdges
170 | return self
171 | }
172 | public var size: ConstraintMakerExtendable {
173 | self.description.attributes += .size
174 | return self
175 | }
176 |
177 | @available(iOS 8.0, *)
178 | public var margins: ConstraintMakerExtendable {
179 | self.description.attributes += .margins
180 | return self
181 | }
182 |
183 | @available(iOS 8.0, *)
184 | public var directionalMargins: ConstraintMakerExtendable {
185 | self.description.attributes += .directionalMargins
186 | return self
187 | }
188 |
189 | @available(iOS 8.0, *)
190 | public var centerWithinMargins: ConstraintMakerExtendable {
191 | self.description.attributes += .centerWithinMargins
192 | return self
193 | }
194 |
195 | }
196 |
--------------------------------------------------------------------------------
/Sources/Debugging.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public extension LayoutConstraint {
31 |
32 | override var description: String {
33 | var description = "<"
34 |
35 | description += descriptionForObject(self)
36 |
37 | if let firstItem = conditionalOptional(from: self.firstItem) {
38 | description += " \(descriptionForObject(firstItem))"
39 | }
40 |
41 | if self.firstAttribute != .notAnAttribute {
42 | description += ".\(descriptionForAttribute(self.firstAttribute))"
43 | }
44 |
45 | description += " \(descriptionForRelation(self.relation))"
46 |
47 | if let secondItem = self.secondItem {
48 | description += " \(descriptionForObject(secondItem))"
49 | }
50 |
51 | if self.secondAttribute != .notAnAttribute {
52 | description += ".\(descriptionForAttribute(self.secondAttribute))"
53 | }
54 |
55 | if self.multiplier != 1.0 {
56 | description += " * \(self.multiplier)"
57 | }
58 |
59 | if self.secondAttribute == .notAnAttribute {
60 | description += " \(self.constant)"
61 | } else {
62 | if self.constant > 0.0 {
63 | description += " + \(self.constant)"
64 | } else if self.constant < 0.0 {
65 | description += " - \(abs(self.constant))"
66 | }
67 | }
68 |
69 | if self.priority.rawValue != 1000.0 {
70 | description += " ^\(self.priority)"
71 | }
72 |
73 | description += ">"
74 |
75 | return description
76 | }
77 |
78 | }
79 |
80 | private func descriptionForRelation(_ relation: LayoutRelation) -> String {
81 | switch relation {
82 | case .equal: return "=="
83 | case .greaterThanOrEqual: return ">="
84 | case .lessThanOrEqual: return "<="
85 | #if swift(>=5.0)
86 | @unknown default: return "unknown"
87 | #endif
88 | }
89 | }
90 |
91 | private func descriptionForAttribute(_ attribute: LayoutAttribute) -> String {
92 | #if canImport(UIKit)
93 | switch attribute {
94 | case .notAnAttribute: return "notAnAttribute"
95 | case .top: return "top"
96 | case .left: return "left"
97 | case .bottom: return "bottom"
98 | case .right: return "right"
99 | case .leading: return "leading"
100 | case .trailing: return "trailing"
101 | case .width: return "width"
102 | case .height: return "height"
103 | case .centerX: return "centerX"
104 | case .centerY: return "centerY"
105 | case .lastBaseline: return "lastBaseline"
106 | case .firstBaseline: return "firstBaseline"
107 | case .topMargin: return "topMargin"
108 | case .leftMargin: return "leftMargin"
109 | case .bottomMargin: return "bottomMargin"
110 | case .rightMargin: return "rightMargin"
111 | case .leadingMargin: return "leadingMargin"
112 | case .trailingMargin: return "trailingMargin"
113 | case .centerXWithinMargins: return "centerXWithinMargins"
114 | case .centerYWithinMargins: return "centerYWithinMargins"
115 | #if swift(>=5.0)
116 | @unknown default: return "unknown"
117 | #endif
118 | }
119 | #else
120 | switch attribute {
121 | case .notAnAttribute: return "notAnAttribute"
122 | case .top: return "top"
123 | case .left: return "left"
124 | case .bottom: return "bottom"
125 | case .right: return "right"
126 | case .leading: return "leading"
127 | case .trailing: return "trailing"
128 | case .width: return "width"
129 | case .height: return "height"
130 | case .centerX: return "centerX"
131 | case .centerY: return "centerY"
132 | case .lastBaseline: return "lastBaseline"
133 | case .firstBaseline: return "firstBaseline"
134 | #if swift(>=5.0)
135 | @unknown default: return "unknown"
136 | #endif
137 | }
138 | #endif
139 | }
140 |
141 | private func conditionalOptional(from object: Optional) -> Optional {
142 | return object
143 | }
144 |
145 | private func conditionalOptional(from object: T) -> Optional {
146 | return Optional.some(object)
147 | }
148 |
149 | private func descriptionForObject(_ object: AnyObject) -> String {
150 | let pointerDescription = String(format: "%p", UInt(bitPattern: ObjectIdentifier(object)))
151 | var desc = ""
152 |
153 | desc += type(of: object).description()
154 |
155 | if let object = object as? ConstraintView {
156 | desc += ":\(object.snp.label() ?? pointerDescription)"
157 | } else if let object = object as? LayoutConstraint {
158 | desc += ":\(object.label ?? pointerDescription)"
159 | } else {
160 | desc += ":\(pointerDescription)"
161 | }
162 |
163 | if let object = object as? LayoutConstraint, let file = object.constraint?.sourceLocation.0, let line = object.constraint?.sourceLocation.1 {
164 | desc += "@\((file as NSString).lastPathComponent)#\(line)"
165 | }
166 |
167 | desc += ""
168 | return desc
169 | }
170 |
--------------------------------------------------------------------------------
/Sources/ConstraintDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintDSL {
32 |
33 | var target: AnyObject? { get }
34 |
35 | func setLabel(_ value: String?)
36 | func label() -> String?
37 |
38 | }
39 | extension ConstraintDSL {
40 |
41 | public func setLabel(_ value: String?) {
42 | objc_setAssociatedObject(self.target as Any, &labelKey, value, .OBJC_ASSOCIATION_COPY_NONATOMIC)
43 | }
44 | public func label() -> String? {
45 | return objc_getAssociatedObject(self.target as Any, &labelKey) as? String
46 | }
47 |
48 | }
49 | private var labelKey: UInt8 = 0
50 |
51 |
52 | public protocol ConstraintBasicAttributesDSL : ConstraintDSL {
53 | }
54 | extension ConstraintBasicAttributesDSL {
55 |
56 | // MARK: Basics
57 |
58 | public var left: ConstraintItem {
59 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left)
60 | }
61 |
62 | public var top: ConstraintItem {
63 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top)
64 | }
65 |
66 | public var right: ConstraintItem {
67 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.right)
68 | }
69 |
70 | public var bottom: ConstraintItem {
71 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom)
72 | }
73 |
74 | public var leading: ConstraintItem {
75 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leading)
76 | }
77 |
78 | public var trailing: ConstraintItem {
79 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailing)
80 | }
81 |
82 | public var width: ConstraintItem {
83 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.width)
84 | }
85 |
86 | public var height: ConstraintItem {
87 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height)
88 | }
89 |
90 | public var centerX: ConstraintItem {
91 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerX)
92 | }
93 |
94 | public var centerY: ConstraintItem {
95 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerY)
96 | }
97 |
98 | public var edges: ConstraintItem {
99 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.edges)
100 | }
101 |
102 | public var directionalEdges: ConstraintItem {
103 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.directionalEdges)
104 | }
105 |
106 | public var horizontalEdges: ConstraintItem {
107 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.horizontalEdges)
108 | }
109 |
110 | public var verticalEdges: ConstraintItem {
111 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.verticalEdges)
112 | }
113 |
114 | public var directionalHorizontalEdges: ConstraintItem {
115 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.directionalHorizontalEdges)
116 | }
117 |
118 | public var directionalVerticalEdges: ConstraintItem {
119 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.directionalVerticalEdges)
120 | }
121 |
122 | public var size: ConstraintItem {
123 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.size)
124 | }
125 |
126 | public var center: ConstraintItem {
127 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center)
128 | }
129 |
130 | }
131 |
132 | public protocol ConstraintAttributesDSL : ConstraintBasicAttributesDSL {
133 | }
134 | extension ConstraintAttributesDSL {
135 |
136 | // MARK: Baselines
137 | @available(*, deprecated, renamed:"lastBaseline")
138 | public var baseline: ConstraintItem {
139 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline)
140 | }
141 |
142 | @available(iOS 8.0, OSX 10.11, *)
143 | public var lastBaseline: ConstraintItem {
144 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline)
145 | }
146 |
147 | @available(iOS 8.0, OSX 10.11, *)
148 | public var firstBaseline: ConstraintItem {
149 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.firstBaseline)
150 | }
151 |
152 | // MARK: Margins
153 |
154 | @available(iOS 8.0, *)
155 | public var leftMargin: ConstraintItem {
156 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leftMargin)
157 | }
158 |
159 | @available(iOS 8.0, *)
160 | public var topMargin: ConstraintItem {
161 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.topMargin)
162 | }
163 |
164 | @available(iOS 8.0, *)
165 | public var rightMargin: ConstraintItem {
166 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.rightMargin)
167 | }
168 |
169 | @available(iOS 8.0, *)
170 | public var bottomMargin: ConstraintItem {
171 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottomMargin)
172 | }
173 |
174 | @available(iOS 8.0, *)
175 | public var leadingMargin: ConstraintItem {
176 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leadingMargin)
177 | }
178 |
179 | @available(iOS 8.0, *)
180 | public var trailingMargin: ConstraintItem {
181 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailingMargin)
182 | }
183 |
184 | @available(iOS 8.0, *)
185 | public var centerXWithinMargins: ConstraintItem {
186 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerXWithinMargins)
187 | }
188 |
189 | @available(iOS 8.0, *)
190 | public var centerYWithinMargins: ConstraintItem {
191 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerYWithinMargins)
192 | }
193 |
194 | @available(iOS 8.0, *)
195 | public var margins: ConstraintItem {
196 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.margins)
197 | }
198 |
199 | @available(iOS 8.0, *)
200 | public var directionalMargins: ConstraintItem {
201 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.directionalMargins)
202 | }
203 |
204 | @available(iOS 8.0, *)
205 | public var centerWithinMargins: ConstraintItem {
206 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerWithinMargins)
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/Sources/ConstraintConstantTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintConstantTarget {
32 | }
33 |
34 | extension CGPoint: ConstraintConstantTarget {
35 | }
36 |
37 | extension CGSize: ConstraintConstantTarget {
38 | }
39 |
40 | extension ConstraintInsets: ConstraintConstantTarget {
41 | }
42 |
43 | #if canImport(UIKit)
44 | @available(iOS 11.0, tvOS 11.0, *)
45 | extension ConstraintDirectionalInsets: ConstraintConstantTarget {
46 | }
47 | #endif
48 |
49 | extension ConstraintConstantTarget {
50 |
51 | internal func constraintConstantTargetValueFor(layoutAttribute: LayoutAttribute) -> CGFloat {
52 | if let value = self as? CGFloat {
53 | return value
54 | }
55 |
56 | if let value = self as? Float {
57 | return CGFloat(value)
58 | }
59 |
60 | if let value = self as? Double {
61 | return CGFloat(value)
62 | }
63 |
64 | if let value = self as? Int {
65 | return CGFloat(value)
66 | }
67 |
68 | if let value = self as? UInt {
69 | return CGFloat(value)
70 | }
71 |
72 | if let value = self as? CGSize {
73 | if layoutAttribute == .width {
74 | return value.width
75 | } else if layoutAttribute == .height {
76 | return value.height
77 | } else {
78 | return 0.0
79 | }
80 | }
81 |
82 | if let value = self as? CGPoint {
83 | #if canImport(UIKit)
84 | switch layoutAttribute {
85 | case .left, .right, .leading, .trailing, .centerX, .leftMargin, .rightMargin, .leadingMargin, .trailingMargin, .centerXWithinMargins:
86 | return value.x
87 | case .top, .bottom, .centerY, .topMargin, .bottomMargin, .centerYWithinMargins, .lastBaseline, .firstBaseline:
88 | return value.y
89 | case .width, .height, .notAnAttribute:
90 | return 0.0
91 | #if swift(>=5.0)
92 | @unknown default:
93 | return 0.0
94 | #endif
95 | }
96 | #else
97 | switch layoutAttribute {
98 | case .left, .right, .leading, .trailing, .centerX:
99 | return value.x
100 | case .top, .bottom, .centerY, .lastBaseline, .firstBaseline:
101 | return value.y
102 | case .width, .height, .notAnAttribute:
103 | return 0.0
104 | #if swift(>=5.0)
105 | @unknown default:
106 | return 0.0
107 | #endif
108 | }
109 | #endif
110 | }
111 |
112 | if let value = self as? ConstraintInsets {
113 | #if canImport(UIKit)
114 | switch layoutAttribute {
115 | case .left, .leftMargin:
116 | return value.left
117 | case .top, .topMargin, .firstBaseline:
118 | return value.top
119 | case .right, .rightMargin:
120 | return -value.right
121 | case .bottom, .bottomMargin, .lastBaseline:
122 | return -value.bottom
123 | case .leading, .leadingMargin:
124 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
125 | case .trailing, .trailingMargin:
126 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
127 | case .centerX, .centerXWithinMargins:
128 | return (value.left - value.right) / 2
129 | case .centerY, .centerYWithinMargins:
130 | return (value.top - value.bottom) / 2
131 | case .width:
132 | return -(value.left + value.right)
133 | case .height:
134 | return -(value.top + value.bottom)
135 | case .notAnAttribute:
136 | return 0.0
137 | #if swift(>=5.0)
138 | @unknown default:
139 | return 0.0
140 | #endif
141 | }
142 | #else
143 | switch layoutAttribute {
144 | case .left:
145 | return value.left
146 | case .top, .firstBaseline:
147 | return value.top
148 | case .right:
149 | return -value.right
150 | case .bottom, .lastBaseline:
151 | return -value.bottom
152 | case .leading:
153 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
154 | case .trailing:
155 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
156 | case .centerX:
157 | return (value.left - value.right) / 2
158 | case .centerY:
159 | return (value.top - value.bottom) / 2
160 | case .width:
161 | return -(value.left + value.right)
162 | case .height:
163 | return -(value.top + value.bottom)
164 | case .notAnAttribute:
165 | return 0.0
166 | #if swift(>=5.0)
167 | @unknown default:
168 | return 0.0
169 | #endif
170 | }
171 | #endif
172 | }
173 |
174 | #if canImport(UIKit)
175 | if #available(iOS 11.0, tvOS 11.0, *), let value = self as? ConstraintDirectionalInsets {
176 | switch layoutAttribute {
177 | case .left, .leftMargin:
178 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.leading : value.trailing
179 | case .top, .topMargin, .firstBaseline:
180 | return value.top
181 | case .right, .rightMargin:
182 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.trailing : -value.leading
183 | case .bottom, .bottomMargin, .lastBaseline:
184 | return -value.bottom
185 | case .leading, .leadingMargin:
186 | return value.leading
187 | case .trailing, .trailingMargin:
188 | return -value.trailing
189 | case .centerX, .centerXWithinMargins:
190 | return (value.leading - value.trailing) / 2
191 | case .centerY, .centerYWithinMargins:
192 | return (value.top - value.bottom) / 2
193 | case .width:
194 | return -(value.leading + value.trailing)
195 | case .height:
196 | return -(value.top + value.bottom)
197 | case .notAnAttribute:
198 | return 0.0
199 | #if swift(>=5.0)
200 | @unknown default:
201 | return 0.0
202 | #else
203 | default:
204 | return 0.0
205 | #endif
206 | }
207 | }
208 | #endif
209 |
210 | return 0.0
211 | }
212 |
213 | }
214 |
--------------------------------------------------------------------------------
/Sources/ConstraintMaker.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public class ConstraintMaker {
31 |
32 | public var left: ConstraintMakerExtendable {
33 | return self.makeExtendableWithAttributes(.left)
34 | }
35 |
36 | public var top: ConstraintMakerExtendable {
37 | return self.makeExtendableWithAttributes(.top)
38 | }
39 |
40 | public var bottom: ConstraintMakerExtendable {
41 | return self.makeExtendableWithAttributes(.bottom)
42 | }
43 |
44 | public var right: ConstraintMakerExtendable {
45 | return self.makeExtendableWithAttributes(.right)
46 | }
47 |
48 | public var leading: ConstraintMakerExtendable {
49 | return self.makeExtendableWithAttributes(.leading)
50 | }
51 |
52 | public var trailing: ConstraintMakerExtendable {
53 | return self.makeExtendableWithAttributes(.trailing)
54 | }
55 |
56 | public var width: ConstraintMakerExtendable {
57 | return self.makeExtendableWithAttributes(.width)
58 | }
59 |
60 | public var height: ConstraintMakerExtendable {
61 | return self.makeExtendableWithAttributes(.height)
62 | }
63 |
64 | public var centerX: ConstraintMakerExtendable {
65 | return self.makeExtendableWithAttributes(.centerX)
66 | }
67 |
68 | public var centerY: ConstraintMakerExtendable {
69 | return self.makeExtendableWithAttributes(.centerY)
70 | }
71 |
72 | @available(*, deprecated, renamed:"lastBaseline")
73 | public var baseline: ConstraintMakerExtendable {
74 | return self.makeExtendableWithAttributes(.lastBaseline)
75 | }
76 |
77 | public var lastBaseline: ConstraintMakerExtendable {
78 | return self.makeExtendableWithAttributes(.lastBaseline)
79 | }
80 |
81 | @available(iOS 8.0, OSX 10.11, *)
82 | public var firstBaseline: ConstraintMakerExtendable {
83 | return self.makeExtendableWithAttributes(.firstBaseline)
84 | }
85 |
86 | @available(iOS 8.0, *)
87 | public var leftMargin: ConstraintMakerExtendable {
88 | return self.makeExtendableWithAttributes(.leftMargin)
89 | }
90 |
91 | @available(iOS 8.0, *)
92 | public var rightMargin: ConstraintMakerExtendable {
93 | return self.makeExtendableWithAttributes(.rightMargin)
94 | }
95 |
96 | @available(iOS 8.0, *)
97 | public var topMargin: ConstraintMakerExtendable {
98 | return self.makeExtendableWithAttributes(.topMargin)
99 | }
100 |
101 | @available(iOS 8.0, *)
102 | public var bottomMargin: ConstraintMakerExtendable {
103 | return self.makeExtendableWithAttributes(.bottomMargin)
104 | }
105 |
106 | @available(iOS 8.0, *)
107 | public var leadingMargin: ConstraintMakerExtendable {
108 | return self.makeExtendableWithAttributes(.leadingMargin)
109 | }
110 |
111 | @available(iOS 8.0, *)
112 | public var trailingMargin: ConstraintMakerExtendable {
113 | return self.makeExtendableWithAttributes(.trailingMargin)
114 | }
115 |
116 | @available(iOS 8.0, *)
117 | public var centerXWithinMargins: ConstraintMakerExtendable {
118 | return self.makeExtendableWithAttributes(.centerXWithinMargins)
119 | }
120 |
121 | @available(iOS 8.0, *)
122 | public var centerYWithinMargins: ConstraintMakerExtendable {
123 | return self.makeExtendableWithAttributes(.centerYWithinMargins)
124 | }
125 |
126 | public var edges: ConstraintMakerExtendable {
127 | return self.makeExtendableWithAttributes(.edges)
128 | }
129 | public var horizontalEdges: ConstraintMakerExtendable {
130 | return self.makeExtendableWithAttributes(.horizontalEdges)
131 | }
132 | public var verticalEdges: ConstraintMakerExtendable {
133 | return self.makeExtendableWithAttributes(.verticalEdges)
134 | }
135 | public var directionalEdges: ConstraintMakerExtendable {
136 | return self.makeExtendableWithAttributes(.directionalEdges)
137 | }
138 | public var directionalHorizontalEdges: ConstraintMakerExtendable {
139 | return self.makeExtendableWithAttributes(.directionalHorizontalEdges)
140 | }
141 | public var directionalVerticalEdges: ConstraintMakerExtendable {
142 | return self.makeExtendableWithAttributes(.directionalVerticalEdges)
143 | }
144 | public var size: ConstraintMakerExtendable {
145 | return self.makeExtendableWithAttributes(.size)
146 | }
147 | public var center: ConstraintMakerExtendable {
148 | return self.makeExtendableWithAttributes(.center)
149 | }
150 |
151 | @available(iOS 8.0, *)
152 | public var margins: ConstraintMakerExtendable {
153 | return self.makeExtendableWithAttributes(.margins)
154 | }
155 |
156 | @available(iOS 8.0, *)
157 | public var directionalMargins: ConstraintMakerExtendable {
158 | return self.makeExtendableWithAttributes(.directionalMargins)
159 | }
160 |
161 | @available(iOS 8.0, *)
162 | public var centerWithinMargins: ConstraintMakerExtendable {
163 | return self.makeExtendableWithAttributes(.centerWithinMargins)
164 | }
165 |
166 | public let item: LayoutConstraintItem
167 | private var descriptions = [ConstraintDescription]()
168 |
169 | internal init(item: LayoutConstraintItem) {
170 | self.item = item
171 | self.item.prepare()
172 | }
173 |
174 | internal func makeExtendableWithAttributes(_ attributes: ConstraintAttributes) -> ConstraintMakerExtendable {
175 | let description = ConstraintDescription(item: self.item, attributes: attributes)
176 | self.descriptions.append(description)
177 | return ConstraintMakerExtendable(description)
178 | }
179 |
180 | internal static func prepareConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
181 | let maker = ConstraintMaker(item: item)
182 | closure(maker)
183 | var constraints: [Constraint] = []
184 | for description in maker.descriptions {
185 | guard let constraint = description.constraint else {
186 | continue
187 | }
188 | constraints.append(constraint)
189 | }
190 | return constraints
191 | }
192 |
193 | internal static func makeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
194 | let constraints = prepareConstraints(item: item, closure: closure)
195 | for constraint in constraints {
196 | constraint.activateIfNeeded(updatingExisting: false)
197 | }
198 | }
199 |
200 | internal static func remakeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
201 | self.removeConstraints(item: item)
202 | self.makeConstraints(item: item, closure: closure)
203 | }
204 |
205 | internal static func updateConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
206 | guard item.constraints.count > 0 else {
207 | self.makeConstraints(item: item, closure: closure)
208 | return
209 | }
210 |
211 | let constraints = prepareConstraints(item: item, closure: closure)
212 | for constraint in constraints {
213 | constraint.activateIfNeeded(updatingExisting: true)
214 | }
215 | }
216 |
217 | internal static func removeConstraints(item: LayoutConstraintItem) {
218 | let constraints = item.constraints
219 | for constraint in constraints {
220 | constraint.deactivateIfNeeded()
221 | }
222 | }
223 |
224 | }
225 |
--------------------------------------------------------------------------------
/Sources/ConstraintAttributes.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | internal struct ConstraintAttributes : OptionSet, ExpressibleByIntegerLiteral {
32 |
33 | typealias IntegerLiteralType = UInt
34 |
35 | internal init(rawValue: UInt) {
36 | self.rawValue = rawValue
37 | }
38 | internal init(_ rawValue: UInt) {
39 | self.init(rawValue: rawValue)
40 | }
41 | internal init(nilLiteral: ()) {
42 | self.rawValue = 0
43 | }
44 | internal init(integerLiteral rawValue: IntegerLiteralType) {
45 | self.init(rawValue: rawValue)
46 | }
47 |
48 | internal private(set) var rawValue: UInt
49 | internal static var allZeros: ConstraintAttributes { return 0 }
50 | internal static func convertFromNilLiteral() -> ConstraintAttributes { return 0 }
51 | internal var boolValue: Bool { return self.rawValue != 0 }
52 |
53 | internal func toRaw() -> UInt { return self.rawValue }
54 | internal static func fromRaw(_ raw: UInt) -> ConstraintAttributes? { return self.init(raw) }
55 | internal static func fromMask(_ raw: UInt) -> ConstraintAttributes { return self.init(raw) }
56 |
57 | // normal
58 |
59 | internal static let none: ConstraintAttributes = 0
60 | internal static let left: ConstraintAttributes = ConstraintAttributes(UInt(1) << 0)
61 | internal static let top: ConstraintAttributes = ConstraintAttributes(UInt(1) << 1)
62 | internal static let right: ConstraintAttributes = ConstraintAttributes(UInt(1) << 2)
63 | internal static let bottom: ConstraintAttributes = ConstraintAttributes(UInt(1) << 3)
64 | internal static let leading: ConstraintAttributes = ConstraintAttributes(UInt(1) << 4)
65 | internal static let trailing: ConstraintAttributes = ConstraintAttributes(UInt(1) << 5)
66 | internal static let width: ConstraintAttributes = ConstraintAttributes(UInt(1) << 6)
67 | internal static let height: ConstraintAttributes = ConstraintAttributes(UInt(1) << 7)
68 | internal static let centerX: ConstraintAttributes = ConstraintAttributes(UInt(1) << 8)
69 | internal static let centerY: ConstraintAttributes = ConstraintAttributes(UInt(1) << 9)
70 | internal static let lastBaseline: ConstraintAttributes = ConstraintAttributes(UInt(1) << 10)
71 |
72 | @available(iOS 8.0, OSX 10.11, *)
73 | internal static let firstBaseline: ConstraintAttributes = ConstraintAttributes(UInt(1) << 11)
74 |
75 | @available(iOS 8.0, *)
76 | internal static let leftMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 12)
77 |
78 | @available(iOS 8.0, *)
79 | internal static let rightMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 13)
80 |
81 | @available(iOS 8.0, *)
82 | internal static let topMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 14)
83 |
84 | @available(iOS 8.0, *)
85 | internal static let bottomMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 15)
86 |
87 | @available(iOS 8.0, *)
88 | internal static let leadingMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 16)
89 |
90 | @available(iOS 8.0, *)
91 | internal static let trailingMargin: ConstraintAttributes = ConstraintAttributes(UInt(1) << 17)
92 |
93 | @available(iOS 8.0, *)
94 | internal static let centerXWithinMargins: ConstraintAttributes = ConstraintAttributes(UInt(1) << 18)
95 |
96 | @available(iOS 8.0, *)
97 | internal static let centerYWithinMargins: ConstraintAttributes = ConstraintAttributes(UInt(1) << 19)
98 |
99 | // aggregates
100 |
101 | internal static let edges: ConstraintAttributes = [.horizontalEdges, .verticalEdges]
102 | internal static let horizontalEdges: ConstraintAttributes = [.left, .right]
103 | internal static let verticalEdges: ConstraintAttributes = [.top, .bottom]
104 | internal static let directionalEdges: ConstraintAttributes = [.directionalHorizontalEdges, .directionalVerticalEdges]
105 | internal static let directionalHorizontalEdges: ConstraintAttributes = [.leading, .trailing]
106 | internal static let directionalVerticalEdges: ConstraintAttributes = [.top, .bottom]
107 | internal static let size: ConstraintAttributes = [.width, .height]
108 | internal static let center: ConstraintAttributes = [.centerX, .centerY]
109 |
110 | @available(iOS 8.0, *)
111 | internal static let margins: ConstraintAttributes = [.leftMargin, .topMargin, .rightMargin, .bottomMargin]
112 |
113 | @available(iOS 8.0, *)
114 | internal static let directionalMargins: ConstraintAttributes = [.leadingMargin, .topMargin, .trailingMargin, .bottomMargin]
115 |
116 | @available(iOS 8.0, *)
117 | internal static let centerWithinMargins: ConstraintAttributes = [.centerXWithinMargins, .centerYWithinMargins]
118 |
119 | internal var layoutAttributes:[LayoutAttribute] {
120 | var attrs = [LayoutAttribute]()
121 | if (self.contains(ConstraintAttributes.left)) {
122 | attrs.append(.left)
123 | }
124 | if (self.contains(ConstraintAttributes.top)) {
125 | attrs.append(.top)
126 | }
127 | if (self.contains(ConstraintAttributes.right)) {
128 | attrs.append(.right)
129 | }
130 | if (self.contains(ConstraintAttributes.bottom)) {
131 | attrs.append(.bottom)
132 | }
133 | if (self.contains(ConstraintAttributes.leading)) {
134 | attrs.append(.leading)
135 | }
136 | if (self.contains(ConstraintAttributes.trailing)) {
137 | attrs.append(.trailing)
138 | }
139 | if (self.contains(ConstraintAttributes.width)) {
140 | attrs.append(.width)
141 | }
142 | if (self.contains(ConstraintAttributes.height)) {
143 | attrs.append(.height)
144 | }
145 | if (self.contains(ConstraintAttributes.centerX)) {
146 | attrs.append(.centerX)
147 | }
148 | if (self.contains(ConstraintAttributes.centerY)) {
149 | attrs.append(.centerY)
150 | }
151 | if (self.contains(ConstraintAttributes.lastBaseline)) {
152 | attrs.append(.lastBaseline)
153 | }
154 |
155 | #if canImport(UIKit)
156 | if (self.contains(ConstraintAttributes.firstBaseline)) {
157 | attrs.append(.firstBaseline)
158 | }
159 | if (self.contains(ConstraintAttributes.leftMargin)) {
160 | attrs.append(.leftMargin)
161 | }
162 | if (self.contains(ConstraintAttributes.rightMargin)) {
163 | attrs.append(.rightMargin)
164 | }
165 | if (self.contains(ConstraintAttributes.topMargin)) {
166 | attrs.append(.topMargin)
167 | }
168 | if (self.contains(ConstraintAttributes.bottomMargin)) {
169 | attrs.append(.bottomMargin)
170 | }
171 | if (self.contains(ConstraintAttributes.leadingMargin)) {
172 | attrs.append(.leadingMargin)
173 | }
174 | if (self.contains(ConstraintAttributes.trailingMargin)) {
175 | attrs.append(.trailingMargin)
176 | }
177 | if (self.contains(ConstraintAttributes.centerXWithinMargins)) {
178 | attrs.append(.centerXWithinMargins)
179 | }
180 | if (self.contains(ConstraintAttributes.centerYWithinMargins)) {
181 | attrs.append(.centerYWithinMargins)
182 | }
183 | #endif
184 |
185 | return attrs
186 | }
187 | }
188 |
189 | internal func + (left: ConstraintAttributes, right: ConstraintAttributes) -> ConstraintAttributes {
190 | return left.union(right)
191 | }
192 |
193 | internal func +=(left: inout ConstraintAttributes, right: ConstraintAttributes) {
194 | left.formUnion(right)
195 | }
196 |
197 | internal func -=(left: inout ConstraintAttributes, right: ConstraintAttributes) {
198 | left.subtract(right)
199 | }
200 |
201 | internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool {
202 | return left.rawValue == right.rawValue
203 | }
204 |
--------------------------------------------------------------------------------
/Sources/Constraint.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if canImport(UIKit)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public final class Constraint {
31 |
32 | internal let sourceLocation: (String, UInt)
33 | internal let label: String?
34 |
35 | private let from: ConstraintItem
36 | private let to: ConstraintItem
37 | private let relation: ConstraintRelation
38 | private let multiplier: ConstraintMultiplierTarget
39 | private var constant: ConstraintConstantTarget {
40 | didSet {
41 | self.updateConstantAndPriorityIfNeeded()
42 | }
43 | }
44 | private var priority: ConstraintPriorityTarget {
45 | didSet {
46 | self.updateConstantAndPriorityIfNeeded()
47 | }
48 | }
49 | public var layoutConstraints: [LayoutConstraint]
50 |
51 | public var isActive: Bool {
52 | set {
53 | if newValue {
54 | activate()
55 | }
56 | else {
57 | deactivate()
58 | }
59 | }
60 |
61 | get {
62 | for layoutConstraint in self.layoutConstraints {
63 | if layoutConstraint.isActive {
64 | return true
65 | }
66 | }
67 | return false
68 | }
69 | }
70 |
71 | // MARK: Initialization
72 |
73 | internal init(from: ConstraintItem,
74 | to: ConstraintItem,
75 | relation: ConstraintRelation,
76 | sourceLocation: (String, UInt),
77 | label: String?,
78 | multiplier: ConstraintMultiplierTarget,
79 | constant: ConstraintConstantTarget,
80 | priority: ConstraintPriorityTarget) {
81 | self.from = from
82 | self.to = to
83 | self.relation = relation
84 | self.sourceLocation = sourceLocation
85 | self.label = label
86 | self.multiplier = multiplier
87 | self.constant = constant
88 | self.priority = priority
89 | self.layoutConstraints = []
90 |
91 | // get attributes
92 | let layoutFromAttributes = self.from.attributes.layoutAttributes
93 | let layoutToAttributes = self.to.attributes.layoutAttributes
94 |
95 | // get layout from
96 | let layoutFrom = self.from.layoutConstraintItem!
97 |
98 | // get relation
99 | let layoutRelation = self.relation.layoutRelation
100 |
101 | for layoutFromAttribute in layoutFromAttributes {
102 | // get layout to attribute
103 | let layoutToAttribute: LayoutAttribute
104 | #if canImport(UIKit)
105 | if layoutToAttributes.count > 0 {
106 | if self.from.attributes == .edges && self.to.attributes == .margins {
107 | switch layoutFromAttribute {
108 | case .left:
109 | layoutToAttribute = .leftMargin
110 | case .right:
111 | layoutToAttribute = .rightMargin
112 | case .top:
113 | layoutToAttribute = .topMargin
114 | case .bottom:
115 | layoutToAttribute = .bottomMargin
116 | default:
117 | fatalError()
118 | }
119 | } else if self.from.attributes == .margins && self.to.attributes == .edges {
120 | switch layoutFromAttribute {
121 | case .leftMargin:
122 | layoutToAttribute = .left
123 | case .rightMargin:
124 | layoutToAttribute = .right
125 | case .topMargin:
126 | layoutToAttribute = .top
127 | case .bottomMargin:
128 | layoutToAttribute = .bottom
129 | default:
130 | fatalError()
131 | }
132 | } else if self.from.attributes == .directionalEdges && self.to.attributes == .directionalMargins {
133 | switch layoutFromAttribute {
134 | case .leading:
135 | layoutToAttribute = .leadingMargin
136 | case .trailing:
137 | layoutToAttribute = .trailingMargin
138 | case .top:
139 | layoutToAttribute = .topMargin
140 | case .bottom:
141 | layoutToAttribute = .bottomMargin
142 | default:
143 | fatalError()
144 | }
145 | } else if self.from.attributes == .directionalMargins && self.to.attributes == .directionalEdges {
146 | switch layoutFromAttribute {
147 | case .leadingMargin:
148 | layoutToAttribute = .leading
149 | case .trailingMargin:
150 | layoutToAttribute = .trailing
151 | case .topMargin:
152 | layoutToAttribute = .top
153 | case .bottomMargin:
154 | layoutToAttribute = .bottom
155 | default:
156 | fatalError()
157 | }
158 | } else if self.from.attributes == self.to.attributes {
159 | layoutToAttribute = layoutFromAttribute
160 | } else {
161 | layoutToAttribute = layoutToAttributes[0]
162 | }
163 | } else {
164 | if self.to.target == nil && (layoutFromAttribute == .centerX || layoutFromAttribute == .centerY) {
165 | layoutToAttribute = layoutFromAttribute == .centerX ? .left : .top
166 | } else {
167 | layoutToAttribute = layoutFromAttribute
168 | }
169 | }
170 | #else
171 | if self.from.attributes == self.to.attributes {
172 | layoutToAttribute = layoutFromAttribute
173 | } else if layoutToAttributes.count > 0 {
174 | layoutToAttribute = layoutToAttributes[0]
175 | } else {
176 | layoutToAttribute = layoutFromAttribute
177 | }
178 | #endif
179 |
180 | // get layout constant
181 | let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute)
182 |
183 | // get layout to
184 | var layoutTo: AnyObject? = self.to.target
185 |
186 | // use superview if possible
187 | if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height {
188 | layoutTo = layoutFrom.superview
189 | }
190 |
191 | // create layout constraint
192 | let layoutConstraint = LayoutConstraint(
193 | item: layoutFrom,
194 | attribute: layoutFromAttribute,
195 | relatedBy: layoutRelation,
196 | toItem: layoutTo,
197 | attribute: layoutToAttribute,
198 | multiplier: self.multiplier.constraintMultiplierTargetValue,
199 | constant: layoutConstant
200 | )
201 |
202 | // set label
203 | layoutConstraint.label = self.label
204 |
205 | // set priority
206 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
207 |
208 | // set constraint
209 | layoutConstraint.constraint = self
210 |
211 | // append
212 | self.layoutConstraints.append(layoutConstraint)
213 | }
214 | }
215 |
216 | // MARK: Public
217 |
218 | @available(*, deprecated, renamed:"activate()")
219 | public func install() {
220 | self.activate()
221 | }
222 |
223 | @available(*, deprecated, renamed:"deactivate()")
224 | public func uninstall() {
225 | self.deactivate()
226 | }
227 |
228 | public func activate() {
229 | self.activateIfNeeded()
230 | }
231 |
232 | public func deactivate() {
233 | self.deactivateIfNeeded()
234 | }
235 |
236 | @discardableResult
237 | public func update(offset: ConstraintOffsetTarget) -> Constraint {
238 | self.constant = offset.constraintOffsetTargetValue
239 | return self
240 | }
241 |
242 | @discardableResult
243 | public func update(inset: ConstraintInsetTarget) -> Constraint {
244 | self.constant = inset.constraintInsetTargetValue
245 | return self
246 | }
247 |
248 | #if canImport(UIKit)
249 | @discardableResult
250 | @available(iOS 11.0, tvOS 11.0, *)
251 | public func update(inset: ConstraintDirectionalInsetTarget) -> Constraint {
252 | self.constant = inset.constraintDirectionalInsetTargetValue
253 | return self
254 | }
255 | #endif
256 |
257 | @discardableResult
258 | public func update(priority: ConstraintPriorityTarget) -> Constraint {
259 | self.priority = priority.constraintPriorityTargetValue
260 | return self
261 | }
262 |
263 | @discardableResult
264 | public func update(priority: ConstraintPriority) -> Constraint {
265 | self.priority = priority.value
266 | return self
267 | }
268 |
269 | @available(*, deprecated, renamed:"update(offset:)")
270 | public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) }
271 |
272 | @available(*, deprecated, renamed:"update(inset:)")
273 | public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) }
274 |
275 | @available(*, deprecated, renamed:"update(priority:)")
276 | public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) }
277 |
278 | @available(*, deprecated, message:"Use update(priority: ConstraintPriorityTarget) instead.")
279 | public func updatePriorityRequired() -> Void {}
280 |
281 | @available(*, deprecated, message:"Use update(priority: ConstraintPriorityTarget) instead.")
282 | public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") }
283 |
284 | @available(*, deprecated, message:"Use update(priority: ConstraintPriorityTarget) instead.")
285 | public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
286 |
287 | @available(*, deprecated, message:"Use update(priority: ConstraintPriorityTarget) instead.")
288 | public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
289 |
290 | // MARK: Internal
291 |
292 | internal func updateConstantAndPriorityIfNeeded() {
293 | for layoutConstraint in self.layoutConstraints {
294 | let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute
295 | layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute)
296 |
297 | let requiredPriority = ConstraintPriority.required.value
298 | if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
299 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
300 | }
301 | }
302 | }
303 |
304 | internal func activateIfNeeded(updatingExisting: Bool = false) {
305 | guard let item = self.from.layoutConstraintItem else {
306 | print("WARNING: SnapKit failed to get from item from constraint. Activate will be a no-op.")
307 | return
308 | }
309 | let layoutConstraints = self.layoutConstraints
310 |
311 | if updatingExisting {
312 | var existingLayoutConstraints: [LayoutConstraint] = []
313 | for constraint in item.constraints {
314 | existingLayoutConstraints += constraint.layoutConstraints
315 | }
316 |
317 | for layoutConstraint in layoutConstraints {
318 | let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
319 | guard let updateLayoutConstraint = existingLayoutConstraint else {
320 | fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)")
321 | }
322 |
323 | let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
324 | updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
325 | }
326 | } else {
327 | NSLayoutConstraint.activate(layoutConstraints)
328 | item.add(constraints: [self])
329 | }
330 | }
331 |
332 | internal func deactivateIfNeeded() {
333 | guard let item = self.from.layoutConstraintItem else {
334 | print("WARNING: SnapKit failed to get from item from constraint. Deactivate will be a no-op.")
335 | return
336 | }
337 | let layoutConstraints = self.layoutConstraints
338 | NSLayoutConstraint.deactivate(layoutConstraints)
339 | item.remove(constraints: [self])
340 | }
341 | }
342 |
--------------------------------------------------------------------------------
/Example-iOS/Example-iOS.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 440B451E25D8696C00334F54 /* ListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 440B451B25D8696C00334F54 /* ListViewController.swift */; };
11 | 440B452125D869A700334F54 /* BasicUIScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 440B451F25D869A700334F54 /* BasicUIScrollViewController.swift */; };
12 | 440B452225D869A700334F54 /* SimpleLayoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 440B452025D869A700334F54 /* SimpleLayoutViewController.swift */; };
13 | 440B452B25D86C0100334F54 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 440B452A25D86C0100334F54 /* SnapKit */; };
14 | 44477D7225D86845009F5E40 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44477D7125D86845009F5E40 /* AppDelegate.swift */; };
15 | 44477D7B25D86846009F5E40 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 44477D7A25D86846009F5E40 /* Assets.xcassets */; };
16 | 44477D7E25D86846009F5E40 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 44477D7C25D86846009F5E40 /* LaunchScreen.storyboard */; };
17 | 5D64AC0228D087AD00FFEC29 /* libswiftCoreGraphics.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D64AC0128D087A400FFEC29 /* libswiftCoreGraphics.tbd */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXFileReference section */
21 | 440B451B25D8696C00334F54 /* ListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListViewController.swift; sourceTree = ""; };
22 | 440B451F25D869A700334F54 /* BasicUIScrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BasicUIScrollViewController.swift; path = demos/BasicUIScrollViewController.swift; sourceTree = ""; };
23 | 440B452025D869A700334F54 /* SimpleLayoutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SimpleLayoutViewController.swift; path = demos/SimpleLayoutViewController.swift; sourceTree = ""; };
24 | 440B452925D86BF200334F54 /* SnapKit */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SnapKit; path = ..; sourceTree = ""; };
25 | 44477D6E25D86845009F5E40 /* Example-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
26 | 44477D7125D86845009F5E40 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
27 | 44477D7A25D86846009F5E40 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
28 | 44477D7D25D86846009F5E40 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
29 | 44477D7F25D86846009F5E40 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
30 | 5D64AC0128D087A400FFEC29 /* libswiftCoreGraphics.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libswiftCoreGraphics.tbd; path = usr/lib/swift/libswiftCoreGraphics.tbd; sourceTree = SDKROOT; };
31 | /* End PBXFileReference section */
32 |
33 | /* Begin PBXFrameworksBuildPhase section */
34 | 44477D6B25D86845009F5E40 /* Frameworks */ = {
35 | isa = PBXFrameworksBuildPhase;
36 | buildActionMask = 2147483647;
37 | files = (
38 | 5D64AC0228D087AD00FFEC29 /* libswiftCoreGraphics.tbd in Frameworks */,
39 | 440B452B25D86C0100334F54 /* SnapKit in Frameworks */,
40 | );
41 | runOnlyForDeploymentPostprocessing = 0;
42 | };
43 | /* End PBXFrameworksBuildPhase section */
44 |
45 | /* Begin PBXGroup section */
46 | 440B452725D86BDF00334F54 /* Frameworks */ = {
47 | isa = PBXGroup;
48 | children = (
49 | 5D64AC0128D087A400FFEC29 /* libswiftCoreGraphics.tbd */,
50 | 440B452925D86BF200334F54 /* SnapKit */,
51 | );
52 | name = Frameworks;
53 | sourceTree = "";
54 | };
55 | 44477D6525D86845009F5E40 = {
56 | isa = PBXGroup;
57 | children = (
58 | 44477D7025D86845009F5E40 /* Example-iOS */,
59 | 44477D6F25D86845009F5E40 /* Products */,
60 | 440B452725D86BDF00334F54 /* Frameworks */,
61 | );
62 | sourceTree = "";
63 | };
64 | 44477D6F25D86845009F5E40 /* Products */ = {
65 | isa = PBXGroup;
66 | children = (
67 | 44477D6E25D86845009F5E40 /* Example-iOS.app */,
68 | );
69 | name = Products;
70 | sourceTree = "";
71 | };
72 | 44477D7025D86845009F5E40 /* Example-iOS */ = {
73 | isa = PBXGroup;
74 | children = (
75 | 44477D7C25D86846009F5E40 /* LaunchScreen.storyboard */,
76 | 44477D7A25D86846009F5E40 /* Assets.xcassets */,
77 | 44477D7F25D86846009F5E40 /* Info.plist */,
78 | 44477D7125D86845009F5E40 /* AppDelegate.swift */,
79 | 440B451B25D8696C00334F54 /* ListViewController.swift */,
80 | 440B451F25D869A700334F54 /* BasicUIScrollViewController.swift */,
81 | 440B452025D869A700334F54 /* SimpleLayoutViewController.swift */,
82 | );
83 | name = "Example-iOS";
84 | sourceTree = "";
85 | };
86 | /* End PBXGroup section */
87 |
88 | /* Begin PBXNativeTarget section */
89 | 44477D6D25D86845009F5E40 /* Example-iOS */ = {
90 | isa = PBXNativeTarget;
91 | buildConfigurationList = 44477D8225D86846009F5E40 /* Build configuration list for PBXNativeTarget "Example-iOS" */;
92 | buildPhases = (
93 | 44477D6A25D86845009F5E40 /* Sources */,
94 | 44477D6B25D86845009F5E40 /* Frameworks */,
95 | 44477D6C25D86845009F5E40 /* Resources */,
96 | );
97 | buildRules = (
98 | );
99 | dependencies = (
100 | );
101 | name = "Example-iOS";
102 | packageProductDependencies = (
103 | 440B452A25D86C0100334F54 /* SnapKit */,
104 | );
105 | productName = "Example-iOS";
106 | productReference = 44477D6E25D86845009F5E40 /* Example-iOS.app */;
107 | productType = "com.apple.product-type.application";
108 | };
109 | /* End PBXNativeTarget section */
110 |
111 | /* Begin PBXProject section */
112 | 44477D6625D86845009F5E40 /* Project object */ = {
113 | isa = PBXProject;
114 | attributes = {
115 | LastSwiftUpdateCheck = 1250;
116 | LastUpgradeCheck = 1250;
117 | TargetAttributes = {
118 | 44477D6D25D86845009F5E40 = {
119 | CreatedOnToolsVersion = 12.5;
120 | };
121 | };
122 | };
123 | buildConfigurationList = 44477D6925D86845009F5E40 /* Build configuration list for PBXProject "Example-iOS" */;
124 | compatibilityVersion = "Xcode 9.3";
125 | developmentRegion = en;
126 | hasScannedForEncodings = 0;
127 | knownRegions = (
128 | en,
129 | Base,
130 | );
131 | mainGroup = 44477D6525D86845009F5E40;
132 | productRefGroup = 44477D6F25D86845009F5E40 /* Products */;
133 | projectDirPath = "";
134 | projectRoot = "";
135 | targets = (
136 | 44477D6D25D86845009F5E40 /* Example-iOS */,
137 | );
138 | };
139 | /* End PBXProject section */
140 |
141 | /* Begin PBXResourcesBuildPhase section */
142 | 44477D6C25D86845009F5E40 /* Resources */ = {
143 | isa = PBXResourcesBuildPhase;
144 | buildActionMask = 2147483647;
145 | files = (
146 | 44477D7E25D86846009F5E40 /* LaunchScreen.storyboard in Resources */,
147 | 44477D7B25D86846009F5E40 /* Assets.xcassets in Resources */,
148 | );
149 | runOnlyForDeploymentPostprocessing = 0;
150 | };
151 | /* End PBXResourcesBuildPhase section */
152 |
153 | /* Begin PBXSourcesBuildPhase section */
154 | 44477D6A25D86845009F5E40 /* Sources */ = {
155 | isa = PBXSourcesBuildPhase;
156 | buildActionMask = 2147483647;
157 | files = (
158 | 440B452225D869A700334F54 /* SimpleLayoutViewController.swift in Sources */,
159 | 440B451E25D8696C00334F54 /* ListViewController.swift in Sources */,
160 | 440B452125D869A700334F54 /* BasicUIScrollViewController.swift in Sources */,
161 | 44477D7225D86845009F5E40 /* AppDelegate.swift in Sources */,
162 | );
163 | runOnlyForDeploymentPostprocessing = 0;
164 | };
165 | /* End PBXSourcesBuildPhase section */
166 |
167 | /* Begin PBXVariantGroup section */
168 | 44477D7C25D86846009F5E40 /* LaunchScreen.storyboard */ = {
169 | isa = PBXVariantGroup;
170 | children = (
171 | 44477D7D25D86846009F5E40 /* Base */,
172 | );
173 | name = LaunchScreen.storyboard;
174 | sourceTree = "";
175 | };
176 | /* End PBXVariantGroup section */
177 |
178 | /* Begin XCBuildConfiguration section */
179 | 44477D8025D86846009F5E40 /* Debug */ = {
180 | isa = XCBuildConfiguration;
181 | buildSettings = {
182 | ALWAYS_SEARCH_USER_PATHS = NO;
183 | CLANG_ANALYZER_NONNULL = YES;
184 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
185 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
186 | CLANG_CXX_LIBRARY = "libc++";
187 | CLANG_ENABLE_MODULES = YES;
188 | CLANG_ENABLE_OBJC_ARC = YES;
189 | CLANG_ENABLE_OBJC_WEAK = YES;
190 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
191 | CLANG_WARN_BOOL_CONVERSION = YES;
192 | CLANG_WARN_COMMA = YES;
193 | CLANG_WARN_CONSTANT_CONVERSION = YES;
194 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
195 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
196 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
197 | CLANG_WARN_EMPTY_BODY = YES;
198 | CLANG_WARN_ENUM_CONVERSION = YES;
199 | CLANG_WARN_INFINITE_RECURSION = YES;
200 | CLANG_WARN_INT_CONVERSION = YES;
201 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
202 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
203 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
204 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
205 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
206 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
207 | CLANG_WARN_STRICT_PROTOTYPES = YES;
208 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
209 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
210 | CLANG_WARN_UNREACHABLE_CODE = YES;
211 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
212 | COPY_PHASE_STRIP = NO;
213 | DEBUG_INFORMATION_FORMAT = dwarf;
214 | ENABLE_STRICT_OBJC_MSGSEND = YES;
215 | ENABLE_TESTABILITY = YES;
216 | GCC_C_LANGUAGE_STANDARD = gnu11;
217 | GCC_DYNAMIC_NO_PIC = NO;
218 | GCC_NO_COMMON_BLOCKS = YES;
219 | GCC_OPTIMIZATION_LEVEL = 0;
220 | GCC_PREPROCESSOR_DEFINITIONS = (
221 | "DEBUG=1",
222 | "$(inherited)",
223 | );
224 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
225 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
226 | GCC_WARN_UNDECLARED_SELECTOR = YES;
227 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
228 | GCC_WARN_UNUSED_FUNCTION = YES;
229 | GCC_WARN_UNUSED_VARIABLE = YES;
230 | IPHONEOS_DEPLOYMENT_TARGET = 14.5;
231 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
232 | MTL_FAST_MATH = YES;
233 | ONLY_ACTIVE_ARCH = YES;
234 | SDKROOT = iphoneos;
235 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
236 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
237 | };
238 | name = Debug;
239 | };
240 | 44477D8125D86846009F5E40 /* Release */ = {
241 | isa = XCBuildConfiguration;
242 | buildSettings = {
243 | ALWAYS_SEARCH_USER_PATHS = NO;
244 | CLANG_ANALYZER_NONNULL = YES;
245 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
247 | CLANG_CXX_LIBRARY = "libc++";
248 | CLANG_ENABLE_MODULES = YES;
249 | CLANG_ENABLE_OBJC_ARC = YES;
250 | CLANG_ENABLE_OBJC_WEAK = YES;
251 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
252 | CLANG_WARN_BOOL_CONVERSION = YES;
253 | CLANG_WARN_COMMA = YES;
254 | CLANG_WARN_CONSTANT_CONVERSION = YES;
255 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
256 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
257 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
258 | CLANG_WARN_EMPTY_BODY = YES;
259 | CLANG_WARN_ENUM_CONVERSION = YES;
260 | CLANG_WARN_INFINITE_RECURSION = YES;
261 | CLANG_WARN_INT_CONVERSION = YES;
262 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
263 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
264 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
265 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
266 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
267 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
268 | CLANG_WARN_STRICT_PROTOTYPES = YES;
269 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
270 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
271 | CLANG_WARN_UNREACHABLE_CODE = YES;
272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
273 | COPY_PHASE_STRIP = NO;
274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
275 | ENABLE_NS_ASSERTIONS = NO;
276 | ENABLE_STRICT_OBJC_MSGSEND = YES;
277 | GCC_C_LANGUAGE_STANDARD = gnu11;
278 | GCC_NO_COMMON_BLOCKS = YES;
279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
281 | GCC_WARN_UNDECLARED_SELECTOR = YES;
282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
283 | GCC_WARN_UNUSED_FUNCTION = YES;
284 | GCC_WARN_UNUSED_VARIABLE = YES;
285 | IPHONEOS_DEPLOYMENT_TARGET = 14.5;
286 | MTL_ENABLE_DEBUG_INFO = NO;
287 | MTL_FAST_MATH = YES;
288 | SDKROOT = iphoneos;
289 | SWIFT_COMPILATION_MODE = wholemodule;
290 | SWIFT_OPTIMIZATION_LEVEL = "-O";
291 | VALIDATE_PRODUCT = YES;
292 | };
293 | name = Release;
294 | };
295 | 44477D8325D86846009F5E40 /* Debug */ = {
296 | isa = XCBuildConfiguration;
297 | buildSettings = {
298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
299 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
300 | CODE_SIGN_STYLE = Automatic;
301 | INFOPLIST_FILE = Info.plist;
302 | IPHONEOS_DEPLOYMENT_TARGET = 11.0;
303 | LD_RUNPATH_SEARCH_PATHS = (
304 | "$(inherited)",
305 | "@executable_path/Frameworks",
306 | );
307 | LIBRARY_SEARCH_PATHS = (
308 | "$(inherited)",
309 | "$(SDKROOT)/usr/lib/swift",
310 | );
311 | PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.Example-iOS";
312 | PRODUCT_NAME = "$(TARGET_NAME)";
313 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
314 | SUPPORTS_MACCATALYST = NO;
315 | SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
316 | SWIFT_VERSION = 5.0;
317 | TARGETED_DEVICE_FAMILY = "1,2,7";
318 | };
319 | name = Debug;
320 | };
321 | 44477D8425D86846009F5E40 /* Release */ = {
322 | isa = XCBuildConfiguration;
323 | buildSettings = {
324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
325 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
326 | CODE_SIGN_STYLE = Automatic;
327 | INFOPLIST_FILE = Info.plist;
328 | IPHONEOS_DEPLOYMENT_TARGET = 11.0;
329 | LD_RUNPATH_SEARCH_PATHS = (
330 | "$(inherited)",
331 | "@executable_path/Frameworks",
332 | );
333 | LIBRARY_SEARCH_PATHS = (
334 | "$(inherited)",
335 | "$(SDKROOT)/usr/lib/swift",
336 | );
337 | PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.Example-iOS";
338 | PRODUCT_NAME = "$(TARGET_NAME)";
339 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
340 | SUPPORTS_MACCATALYST = NO;
341 | SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
342 | SWIFT_VERSION = 5.0;
343 | TARGETED_DEVICE_FAMILY = "1,2,7";
344 | };
345 | name = Release;
346 | };
347 | /* End XCBuildConfiguration section */
348 |
349 | /* Begin XCConfigurationList section */
350 | 44477D6925D86845009F5E40 /* Build configuration list for PBXProject "Example-iOS" */ = {
351 | isa = XCConfigurationList;
352 | buildConfigurations = (
353 | 44477D8025D86846009F5E40 /* Debug */,
354 | 44477D8125D86846009F5E40 /* Release */,
355 | );
356 | defaultConfigurationIsVisible = 0;
357 | defaultConfigurationName = Release;
358 | };
359 | 44477D8225D86846009F5E40 /* Build configuration list for PBXNativeTarget "Example-iOS" */ = {
360 | isa = XCConfigurationList;
361 | buildConfigurations = (
362 | 44477D8325D86846009F5E40 /* Debug */,
363 | 44477D8425D86846009F5E40 /* Release */,
364 | );
365 | defaultConfigurationIsVisible = 0;
366 | defaultConfigurationName = Release;
367 | };
368 | /* End XCConfigurationList section */
369 |
370 | /* Begin XCSwiftPackageProductDependency section */
371 | 440B452A25D86C0100334F54 /* SnapKit */ = {
372 | isa = XCSwiftPackageProductDependency;
373 | productName = SnapKit;
374 | };
375 | /* End XCSwiftPackageProductDependency section */
376 | };
377 | rootObject = 44477D6625D86845009F5E40 /* Project object */;
378 | }
379 |
--------------------------------------------------------------------------------