Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Created June 14, 2016 12:54
Show Gist options
  • Save samuelbeek/3fd61dae6d9e0c3a4ed81c2a17a4ca9c to your computer and use it in GitHub Desktop.
Save samuelbeek/3fd61dae6d9e0c3a4ed81c2a17a4ca9c to your computer and use it in GitHub Desktop.
Making Cartography compile faster.
//
// CartographyExtensions.swift
// portkey
//
// Created by Samuel Beek on 14/06/16.
//
// Note: still WIP. I only dealt with the equality operator (==), haven't worked on <= and ~ yet.
// But adding this won't be bad for you project, it saves me 70% compile time per block on avarage.
import Foundation
public func makeEqual<P: RelativeEquality>(lhs: P, _ rhs: Expression<P>) -> NSLayoutConstraint {
return lhs.context.addConstraint(lhs, coefficients: rhs.coefficients[0], to: rhs.value)
}
public func makeEqual<P: RelativeEquality>(lhs: P, _ rhs: P) -> NSLayoutConstraint {
return lhs.context.addConstraint(lhs, to: rhs)
}
public func makeEqual(lhs: NumericalEquality, _ rhs: CGFloat) -> NSLayoutConstraint {
return lhs.context.addConstraint(lhs, coefficients: Coefficients(1, rhs))
}
public func makeEqual<P: RelativeCompoundEquality>(lhs: P, _ rhs: P) -> [NSLayoutConstraint] {
return lhs.context.addConstraint(lhs, to: rhs)
}
@pedromcunha
Copy link

Is this still useable? I keep getting
'addConstraint' is inaccessible due to 'internal' protection level.

@acrookston
Copy link

This gist inspired a pull-request I created on Cartography, see here: robb/Cartography#293. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment