Skip to content

Migrating from PureLayout v2.x to v3.0

Tyler Fox edited this page Aug 17, 2015 · 19 revisions

PureLayout v3.0.0

PureLayout v3.0.0 is a major release, with new APIs, enhancements, and other changes. See the release notes for an overview of changes.

Moved APIs

The most significant breaking change in PureLayout v3.0.0 is the move of the following class methods from their original location on UIView/NSView to their new location on NSLayoutConstraint:

  • +[autoCreateConstraintsWithoutInstalling:]
  • +[autoSetPriority:forConstraints:]
  • +[autoSetIdentifier:forConstraints:]

When migrating existing code using v2.x to v3.0.0, you just need to change the class name at each call site. For example, this code using PureLayout v2.x:

[UIView autoSetPriority:UILayoutPriorityDefaultHigh forConstraints:^{ /* ... */ }];

Simply changes to the following with PureLayout v3.0.0:

[NSLayoutConstraint autoSetPriority:UILayoutPriorityDefaultHigh forConstraints:^{ /* ... */ }];

Easily Convert using Find & Replace

You can use a global find & replace in Xcode with the following regular expression patterns to quickly & automatically convert older v2.x API calls to their new v3.0 versions.

Objective-C

Find Regex Pattern:

(\[\s*)(UIView|NSView|ALView)(\s+(autoCreateConstraintsWithoutInstalling|autoSetPriority|autoSetIdentifier):)

Replace Regex Pattern:

$1NSLayoutConstraint$3

Swift

Find Regex Pattern:

(UIView|NSView|ALView)(\w*\.\w*(autoCreateConstraintsWithoutInstalling|autoSetPriority|autoSetIdentifier)\w*\()

Replace Regex Pattern:

NSLayoutConstraint$2

Removed APIs

The APIs that were deprecated in PureLayout v2.0.0 have been removed entirely. See this section of the v1.x to v2.0 Migration Guide for more details. You shouldn't have been using those anymore, right? 😉

Nullability Annotations and Generics

Upgrading from PureLayout v2.x to v3.0.0 may cause compilation errors or warnings with existing code due to the addition of nullability annotations and generics across the entire API. You should make the necessary fixes to your code.

For example, because view.superview is an Optional type in Swift (nullable in Objective-C), you must convert that to a non-Optional type (e.g. using ! to force unwrap) before using it with PureLayout:

view1.autoMatchDimension(.Width, toDimension: .Width, ofView: view1.superview!)

Other Changes

None of the other changes in PureLayout v3.0.0 should require any changes to existing code using v2.x. However, take a look through the v3.0.0 release notes to learn about the new APIs that you can adopt.

Clone this wiki locally