← Back to PureLayout/PureLayout

How to Deploy & Use PureLayout/PureLayout

PureLayout Deployment & Usage Guide

1. Prerequisites

Development Environment

  • Xcode: Version 5.0 or higher (fully compatible with Xcode 7.0+)
  • iOS SDK: iOS 6.0 or higher (iOS 9.0+ for full compatibility)
  • macOS SDK: OS X 10.7 or higher (OS X 10.11+ for full compatibility)
  • Language Support: Objective-C or Swift (any version)

Dependency Managers (Optional)

  • CocoaPods: Version 0.36 or higher (for CocoaPods integration)
  • Carthage: Latest stable version (for Carthage integration)

2. Installation

Choose one of the following integration methods:

Option A: CocoaPods (Recommended)

  1. Add PureLayout to your Podfile:

    pod 'PureLayout'
    
  2. Install the pod:

    pod install
    
  3. Open the generated .xcworkspace file:

    open YourProject.xcworkspace
    

Option B: Carthage

  1. Add PureLayout to your Cartfile:

    github "PureLayout/PureLayout"
    
  2. Run Carthage update:

    carthage update
    
  3. Drag the built PureLayout.framework from Carthage/Build/iOS/ (or Mac/) into your project's "Linked Frameworks and Libraries" section.

  4. Add a "Copy Files" build phase to copy the framework to your app bundle (iOS only).

Option C: Manual Installation

  1. Download the source files from the PureLayout/PureLayout repository.

  2. Copy the contents of the PureLayout/PureLayout directory into your Xcode project.

  3. Ensure the files are added to your target's "Compile Sources" build phase.

3. Configuration

Objective-C Projects

Import the umbrella header in your implementation files:

#import "PureLayout.h"

If using CocoaPods with frameworks or Carthage:

#import <PureLayout/PureLayout.h>

Or with Modules enabled:

@import PureLayout;

Swift Projects

With CocoaPods (use_frameworks! enabled) or Carthage:

import PureLayout

Without use_frameworks! (CocoaPods): Create a bridging header (YourProject-Bridging-Header.h) and add:

#import "PureLayout.h"

App Extensions Configuration

For App Extensions (Today widgets, Share extensions, etc.), you must prevent usage of unavailable APIs:

  1. Add PURELAYOUT_APP_EXTENSIONS to your "Preprocessor Macros" build settings for the extension target.
  2. This disables methods that access -[UIView window] or -[NSView window], which are unavailable in extensions.

4. Build & Run

Basic Usage Example

Create constraints programmatically using the auto... prefixed methods:

Objective-C:

UIView *view1 = [[UIView alloc] initForAutoLayout];
[self.view addSubview:view1];

// Pin edges to superview with 20pt insets
[view1 autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(20, 20, 20, 20)];

// Center in superview
[view1 autoCenterInSuperview];

// Set specific dimensions
[view1 autoSetDimensionsToSize:CGSizeMake(200, 100)];

Swift:

let view1 = UIView(forAutoLayout: ())
self.view.addSubview(view1)

// Pin edges to superview with 20pt insets
view1.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))

// Center in superview
view1.autoCenterInSuperview()

// Set specific dimensions
view1.autoSetDimensions(to: CGSize(width: 200, height: 100))

Key API Patterns

All public methods use the auto... prefix for easy autocomplete discovery:

  • Edge Constraints: autoPinEdgeToSuperviewEdge:withInset:, autoPinEdge:toEdge:ofView:
  • Dimension Constraints: autoSetDimension:toSize:, autoMatchDimension:toDimension:ofView:
  • Position Constraints: autoCenterInSuperview, autoAlignAxis:toSameAxisOfView:
  • Batch Constraints: autoSetViewsDimension:toSize: (for NSArray of views)

Running Example Apps

The repository includes example projects demonstrating usage:

  1. Clone the repository:

    git clone https://github.com/PureLayout/PureLayout.git
    cd PureLayout
    
  2. Open the example project:

    open PureLayout/Example-iOS/PureLayout.xcworkspace
    
  3. Build and run the example app on your chosen simulator or device.

5. Deployment

App Store Submission

PureLayout is safe for App Store submission:

  1. No private API usage: PureLayout uses only public iOS/macOS APIs.
  2. Dynamic Frameworks: If using Carthage or CocoaPods with use_frameworks!, ensure frameworks are properly embedded.
  3. Bitcode: PureLayout supports Bitcode (enabled by default in modern Xcode projects).

App Extensions Deployment

When deploying App Extensions (iOS) or App Extensions (macOS):

  1. Ensure PURELAYOUT_APP_EXTENSIONS is defined in your extension target's build settings.
  2. Verify the PureLayout source files are included in both your main app target and extension target (if sharing code).
  3. Note that some convenience methods (those accessing -[UIView window]) will be unavailable in extensions.

Version Management

Pin to specific versions in dependency managers:

CocoaPods:

pod 'PureLayout', '~> 3.0'

Carthage:

github "PureLayout/PureLayout" ~> 3.0

6. Troubleshooting

Installation Issues

CocoaPods "Unable to find a specification" error:

pod repo update
pod install

Carthage build failures: Ensure you have the latest Carthage version:

brew update
brew upgrade carthage

Manual installation "file not found" errors: Verify that the PureLayout source files are added to your target's "Compile Sources" build phase (Build Phases > Compile Sources).

Import/Module Issues

"Module 'PureLayout' not found" (Swift):

  • If using CocoaPods without use_frameworks!: Ensure you have a bridging header importing PureLayout.h.
  • If using Carthage: Ensure the framework is added to "Embedded Binaries" in target settings.

"Undefined symbols for architecture" linker errors:

  • Verify the PureLayout library is linked in your target's "Link Binary With Libraries" build phase.
  • For manual installation, ensure -ObjC is added to "Other Linker Flags" in Build Settings.

Runtime Issues

Constraints breaking at runtime:

  • Ensure views are added to the view hierarchy before creating constraints: [parentView addSubview:childView].
  • Check for conflicting constraints by examining the console output for "Unable to simultaneously satisfy constraints" errors.
  • Use autoInstall and autoRemove for dynamic constraint management instead of directly setting active property if supporting iOS 7.

App Extension crashes on launch:

  • Verify PURELAYOUT_APP_EXTENSIONS is defined in the preprocessor macros for your extension target.
  • Check that you are not calling methods that access -[UIView window] in extension contexts.

Performance Issues

Slow layout performance:

  • Minimize constraint creation in layoutSubviews or viewDidLayoutSubviews methods.
  • Store references to constraints that will change frequently instead of recreating them.
  • Use autoSetIdentifier: to name constraints for easier debugging in Instruments.

Getting Help

  • Documentation: Explore header files in PureLayout/PureLayout for complete API documentation.
  • Issues: Report bugs on GitHub Issues.
  • Wiki: Check the PureLayout Wiki for additional guides including App Extension setup.