<commit_before># FormulaStyleConstraint
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/fhisa/FormulaStyleConstraint/master/LICENSE) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

 (*[Japanese](https://github.com/fhisa/FormulaStyleConstraint/blob/master/README-ja.md)*)

FormulaStyleConstraint is a framework to simplify the definition of automatic layout constraints in a Swift program for iOS.
Using this framework, it is possible to define the automatic layout constraints as a simple equation.

## Code Examples

### Basic usage

Using the framework, a layout constraint that "the width of the view A is equal to minus 4.0 to 50% of the width of the Views B" follows:
```swift
viewA[.Width] == 0.5 * viewB[.Width] - 4.0
```
This is the same layout constraints with the following code:
```swift
NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewB, attribute: .Width,
    multiplier: 0.5, constant: -4.0)
```

### e.g. Aspect ratio

A layout constraint that "the aspect ratio of the view A is 3:4" follows:
```swift
viewA[.Width] * 3.0 == viewA[.Height] * 4.0
```
This is the same layout constraints with the following code:
```swift
NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewA, attribute: .Height,
    multiplier: 4.0/3.0, constant: 0.0)
```

### e.g. Specify the priority

The framework has priority specification operator `~` like the following.
```swift
innerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0
```
This is the same layout constraints with the following code:
```swift
let constraint = NSLayoutConstraint(
    item: innerView, attribute: .Leading,
    relatedBy: .Equal,
    toItem: outerView, attribute: .Leading,
    multiplier: 1.0, constant: 4.0)
constraint.priority = 750.0
// -> constraint
```

Please refer to the code for the [sample application](https://github.com/fhisa/FormulaStyleConstraint/blob/master/SampleApp/ViewController.swift) and [test case](https://github.com/fhisa/FormulaStyleConstraint/blob/master/FormulaStyleConstraintTests/FormulaStyleConstraintTests.swift), too.

## Refrence Guide

### ConstraintTerm

ConstraintTerm means a term that contains a view in the right side or the left side of a layout constraint.
For example, a ConstraintTerm representing the width `.Width` of view `viewA`:
```swift
viewA[.Width]
```
`viewA` is a UIView instance object, `.Width` is a `NSLayoutAttribute` value.
ConstraintTerm is defined as a structure such as the following:
```swift
public struct ConstraintTerm
{
    let view: UIView?
    let attribute: NSLayoutAttribute
    var multiplier: CGFloat = 1.0
    var constant: CGFloat = 0.0
}
```

### Operators

*The following table, CONSTANT means CGFloat value*

| operator | lhs | rhs | value | semantics |
|:-----:|:---------------|:---------------|:---------------|:--|
| +     | ConstraintTerm | CONSTANT       | ConstraintTerm | add rhs value to lhs.constant |
| +     | CONSTANT       | ConstraintTerm | ConstraintTerm | add lhs value to rhs.constant |
| -     | ConstraintTerm | CONSTANT       | ConstraintTerm | subtract rhs value from lhs.constant |
| *     | ConstraintTerm | CONSTANT       | ConstraintTerm | multiply rhs value to lhs.multiplier and lhs.constant |
| *     | CONSTANT       | ConstraintTerm | ConstraintTerm | multiply lhs value to rhs.multiplier and rhs.constant |
| ==    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is equal to lhs" |
| ==    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| ==    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| <=    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is less than or equal to lhs" |
| <=    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| <=    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| >=    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is greater than or equal to lhs" |
| >=    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| >=    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| ~     | NSLayoutConstraint | CONSTANT(Float) | NSLayoutConstraint | Change the priority of a layout constraint, and return the constraint |

## Requirements

- Swift 1.2 (Xcode 6.3 or later)
- iOS 8 or later (by Carthage) / iOS 7 (by coping the source files directly)

## Installation

There are two options.

### Using Carthage (iOS 8 or later)

Using [Carthage](https://github.com/Carthage/Carthage), it's easy to add FormulaStyleConstraint to the project.

- Add `github "fhisa/FormulaStyleConstraint"` to your Cartfile.
- Run `carthage update`
- Add FormulaStyleConstraint.framework in Carthage/Build/iOS to your Xcode project.

### Copying source files directly (iOS 7)

- Add this repository as a git submodule:
   ```shell
   $ git submodule add https://github.com/fhisa/FormulaStyleConstraint.git PATH_TO_SUBMODULE
   // or
   $ carthage update --use-submodules
   ```
- Then just add references of FormulaStyleConstraint/*.swift to your Xcode project.


Mainly the following methods:
- Use [Carthage](https://github.com/Carthage/Carthage)
- Git Submodule
- Add source files directly to a project (for iOS 7)

## TODO

- Mac OS X support
- [CocoaPods](https://cocoapods.org) support

## license

FormulaStyleConstraint is released under the [MIT license](https://github.com/fhisa/FormulaStyleConstraint/blob/master/LICENSE).<commit_msg>trivial change<commit_after># FormulaStyleConstraint
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/fhisa/FormulaStyleConstraint/master/LICENSE) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

 (*[Japanese](https://github.com/fhisa/FormulaStyleConstraint/blob/master/README-ja.md)*)

FormulaStyleConstraint is a framework to simplify the definition of automatic layout constraints in a Swift program for iOS.
Using this framework, it is possible to define the automatic layout constraints as a simple equation.

## Code Examples

### Basic usage

Using the framework, a layout constraint that "the width of the view A is equal to minus 4.0 to 50% of the width of the Views B" follows:
```swift
viewA[.Width] == 0.5 * viewB[.Width] - 4.0
```
This is the same layout constraints with the following code:
```swift
NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewB, attribute: .Width,
    multiplier: 0.5, constant: -4.0)
```

### e.g. Aspect ratio

A layout constraint that "the aspect ratio of the view A is 3:4" follows:
```swift
viewA[.Width] * 3.0 == viewA[.Height] * 4.0
```
This is the same layout constraints with the following code:
```swift
NSLayoutConstraint(
    item: viewA, attribute: .Width,
    relatedBy: .Equal,
    toItem: viewA, attribute: .Height,
    multiplier: 4.0/3.0, constant: 0.0)
```

### e.g. Specify the priority

The framework has priority specification operator `~` like the following.
```swift
innerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0
```
This is the same layout constraints with the following code:
```swift
let constraint = NSLayoutConstraint(
    item: innerView, attribute: .Leading,
    relatedBy: .Equal,
    toItem: outerView, attribute: .Leading,
    multiplier: 1.0, constant: 4.0)
constraint.priority = 750.0
// -> constraint
```

Please refer to the code for the [sample application](https://github.com/fhisa/FormulaStyleConstraint/blob/master/SampleApp/ViewController.swift) and [test case](https://github.com/fhisa/FormulaStyleConstraint/blob/master/FormulaStyleConstraintTests/FormulaStyleConstraintTests.swift), too.

## Refrence Guide

### ConstraintTerm

ConstraintTerm means a term that contains a view in the right side or the left side of a layout constraint.
For example, a ConstraintTerm representing the width `.Width` of view `viewA`:
```swift
viewA[.Width]
```
`viewA` is a UIView instance object, `.Width` is a `NSLayoutAttribute` value.
ConstraintTerm is defined as a structure such as the following:
```swift
public struct ConstraintTerm
{
    let view: UIView?
    let attribute: NSLayoutAttribute
    var multiplier: CGFloat = 1.0
    var constant: CGFloat = 0.0
}
```

### Operators

*The following table, CONSTANT means CGFloat value*

| operator | lhs | rhs | value | semantics |
|:-----:|:---------------|:---------------|:---------------|:--|
| +     | ConstraintTerm | CONSTANT       | ConstraintTerm | add rhs value to lhs.constant |
| +     | CONSTANT       | ConstraintTerm | ConstraintTerm | add lhs value to rhs.constant |
| -     | ConstraintTerm | CONSTANT       | ConstraintTerm | subtract rhs value from lhs.constant |
| *     | ConstraintTerm | CONSTANT       | ConstraintTerm | multiply rhs value to lhs.multiplier and lhs.constant |
| *     | CONSTANT       | ConstraintTerm | ConstraintTerm | multiply lhs value to rhs.multiplier and rhs.constant |
| ==    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is equal to lhs" |
| ==    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| ==    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| <=    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is less than or equal to lhs" |
| <=    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| <=    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| >=    | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is greater than or equal to lhs" |
| >=    | ConstraintTerm | CONSTANT       | NSLayoutConstraint | ditto |
| >=    | CONSTANT       | ConstraintTerm | NSLayoutConstraint | ditto |
| ~     | NSLayoutConstraint | CONSTANT(Float) | NSLayoutConstraint | Change the priority of a layout constraint, and return the constraint |

## Requirements

- Swift 1.2 (Xcode 6.3 or later)
- iOS 8 or later (by Carthage) / iOS 7 (by coping the source files directly)

## Installation

There are two options.

### Using Carthage (iOS 8 or later)

Using [Carthage](https://github.com/Carthage/Carthage), it's easy to add FormulaStyleConstraint to the project.

- Add `github "fhisa/FormulaStyleConstraint"` to your Cartfile.
- Run `carthage update`
- Add FormulaStyleConstraint.framework in Carthage/Build/iOS to your Xcode project.

### Copying source files directly (iOS 7)

- Add this repository as a git submodule:
```shell
$ git submodule add https://github.com/fhisa/FormulaStyleConstraint.git PATH_TO_SUBMODULE
// or
$ carthage update --use-submodules
```
- Then just add references of FormulaStyleConstraint/*.swift to your Xcode project.


Mainly the following methods:
- Use [Carthage](https://github.com/Carthage/Carthage)
- Git Submodule
- Add source files directly to a project (for iOS 7)

## TODO

- Mac OS X support
- [CocoaPods](https://cocoapods.org) support

## license

FormulaStyleConstraint is released under the [MIT license](https://github.com/fhisa/FormulaStyleConstraint/blob/master/LICENSE).
{'fraction_non_alphanumeric': 0.11723411723411724, 'fraction_numerical': 0.009477009477009477, 'mean_word_length': 3.8518518518518516, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 24, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5336862', 'n_tokens_mistral': 3524, 'n_tokens_neox': 3352, 'n_words': 1108}