Swiftpack.co - Package - SnapKit/SnapKit

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X.

Build Status Platform Cocoapods Compatible Carthage compatible

⚠️ To use with Swift 4.x please ensure you are using >= 4.0.0 ⚠️

⚠️ To use with Swift 5.x please ensure you are using >= 5.0.0 ⚠️

Contents

Requirements

  • iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+
  • Xcode 10.0+
  • Swift 4.0+

Communication

  • If you need help, use Stack Overflow. (Tag 'snapkit')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build SnapKit 4.0.0+.

To integrate SnapKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'SnapKit', '~> 5.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SnapKit into your Xcode project using Carthage, specify it in your Cartfile:

github "SnapKit/SnapKit" ~> 5.0.0

Run carthage update to build the framework and drag the built SnapKit.framework into your Xcode project.

Swift Package Manager

Swift 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.

Xcode 11+ is required to build SnapKit using Swift Package Manager.

To integrate SnapKit into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
]

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate SnapKit into your project manually.


Usage

Quick Start

import SnapKit

class MyViewController: UIViewController {

    lazy var box = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(box)
        box.backgroundColor = .green
        box.snp.makeConstraints { (make) -> Void in
           make.width.height.equalTo(50)
           make.center.equalTo(self.view)
        }
    }

}

Playground

You can try SnapKit in Playground.

Note:

To try SnapKit in playground, open SnapKit.xcworkspace and build SnapKit.framework for any simulator first.

Resources

Credits

License

SnapKit is released under the MIT license. See LICENSE for details.

Github

link
Stars: 17068

Dependencies

Used By

Total: 0

Releases

SnapKit 5.0.1 -

  • Fixes a regression caused by #574
  • Adds Playground #608 (thanks to @ShivaHuang)
  • Updates SwiftPM support #615 (thanks to @maxxfrazer)
  • Adds .directionalEdges and .directionalMargins #595 (thanks to @jctrouble)
  • Make ConstraintViewDSL content priorities non mutational #586 (thanks to @nekrich)

Swift 5.0.0 -

• Official support for Swift 5.0 • Min version is now iOS 10.0, tvOS 10.0 and macOS 10.12

SnapKit 4.2.0 -

  • Official Swift 4.2 compatibility release

SnapKit 4.0.1 -

  • Compatibility with Xcode 10

Swift 4 + Xcode 9 -

This is a compatibility release to target Swift 4 and Xcode 9. It contains no new features only syntax changes required for Swift 4 and Xcode 9!

Bug fixes & Priorities -

  • Added isActive to Constraint so you can see if there are any active NSLayoutConstraint's that are currently active as a result of the backing constraint.
  • Made Constraint layoutConstraints public again so you can publicly access the layout constraints. Use with caution as SnapKit expects ownership of these.
  • Fixed bug with contentCompressionResistanceHorizontalPriority (#387)
  • Fixed missing topMargin with contentCompressionResistanceHorizontalPriority (#393)
  • Added more robust priority support (#345)

Maker for Guides -

ConstraintMaker for UILayoutGuide's

  • You can now use a UILayoutGuide/NSLayoutGuide much like a UIView with the familiar makeConstraints, remakeConstraints, updateConstraints, and removeConstraints API.

Bug Fixes

  • Fixed memory leaks and circular references

More Bug Fixes -

Bug Fixes

  • Fix Carthage build compatibility
  • Adds topMargin back in to ConstraintMaker
  • Adds equalToSuperview(), lessThanOrEqualToSuperview(), greaterThanOrEqualToSuperview()
  • Doing equalTo(CGPoint) ensures superview + offset from top left.

Swift 2.3 -

A tagged release for Swift 2.3!

Mostly Bug Fixes -

Breaking Changes

  • Debug labels must now use a function rather than a property. snp.label = "" is now snp.setLabel("")

Bug Fixes

  • Fixed small memory leaks on all constraints #310
  • Fixed macOS bug preventing make.edges.equalTo(other.snp.edges) #309
  • Fixed bug preventing debug labels from being set. You must now use setLabel() #313
  • Fixed incorrect constant values when using leading/trailing and UIEdgeInsets #316

SnapKit 3.0.0 - Swift 3.0 Release -

SnapKit 3.0 is a complete re-write to take advantage of modern Swift 3.0 as well as clean up the API. As such please use with caution and check your apps thoroughly

Breaking

  • iOS 7.0 support has been removed
  • install and uninstall have been deprecated, use activate and deactivate instead
  • DSL is now accessed through .snp.* rather than .snp_*. For example view.snp.makeConstraints { }
  • Constraints are now updated through update(offset:), update(inset:) and update(priority:)
  • .inset() will no longer take CGPoint or CGSize as input
  • .offset() will no longer take CGPoint, CGSize, EdgeInsets as input
  • updateConstraints will no longer allow creating new constraints unless there are no existing constraints for the view. If it does generate new constraints it will throw a fatal error.
  • UIEdgeInsets are now have their right and bottom value inverted for more natural results such as make.edges.equalTo(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)).inset()

Enhancements

  • Debugging output has been improved to show exact file/line number from which the broken constraint was created
  • Exceptions thrown during constraint creation have been replaced with fatalError with better output
  • Constraints are now installed through NSLayoutConstraint.activate and what view they are added to is now deferred to UIKit
  • Added var contentHugging<Axis>Priority: CGFloat to make
  • Added var contentCompressionResistance<Axis>Priority: CGFloat to make
  • Added support for UILayoutGuide via make.left.equalTo(guide.snp.top)
  • Added support for constraining edges to margins or vice versa via make.edges.equalTo(other.snp.margins)