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)
-
Add PureLayout to your
Podfile:pod 'PureLayout' -
Install the pod:
pod install -
Open the generated
.xcworkspacefile:open YourProject.xcworkspace
Option B: Carthage
-
Add PureLayout to your
Cartfile:github "PureLayout/PureLayout" -
Run Carthage update:
carthage update -
Drag the built
PureLayout.frameworkfromCarthage/Build/iOS/(orMac/) into your project's "Linked Frameworks and Libraries" section. -
Add a "Copy Files" build phase to copy the framework to your app bundle (iOS only).
Option C: Manual Installation
-
Download the source files from the PureLayout/PureLayout repository.
-
Copy the contents of the
PureLayout/PureLayoutdirectory into your Xcode project. -
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:
- Add
PURELAYOUT_APP_EXTENSIONSto your "Preprocessor Macros" build settings for the extension target. - 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:
-
Clone the repository:
git clone https://github.com/PureLayout/PureLayout.git cd PureLayout -
Open the example project:
open PureLayout/Example-iOS/PureLayout.xcworkspace -
Build and run the example app on your chosen simulator or device.
5. Deployment
App Store Submission
PureLayout is safe for App Store submission:
- No private API usage: PureLayout uses only public iOS/macOS APIs.
- Dynamic Frameworks: If using Carthage or CocoaPods with
use_frameworks!, ensure frameworks are properly embedded. - Bitcode: PureLayout supports Bitcode (enabled by default in modern Xcode projects).
App Extensions Deployment
When deploying App Extensions (iOS) or App Extensions (macOS):
- Ensure
PURELAYOUT_APP_EXTENSIONSis defined in your extension target's build settings. - Verify the PureLayout source files are included in both your main app target and extension target (if sharing code).
- 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 importingPureLayout.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
-ObjCis 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
autoInstallandautoRemovefor dynamic constraint management instead of directly settingactiveproperty if supporting iOS 7.
App Extension crashes on launch:
- Verify
PURELAYOUT_APP_EXTENSIONSis 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
layoutSubviewsorviewDidLayoutSubviewsmethods. - 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/PureLayoutfor complete API documentation. - Issues: Report bugs on GitHub Issues.
- Wiki: Check the PureLayout Wiki for additional guides including App Extension setup.