<commit_before>//
//  Stevia+GetConstraint.swift
//  Stevia
//
//  Created by <NAME> on 12/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public extension UIView {
    
    public var leftConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Left)
    }
    
    public var rightConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Right)
    }
    
    public var topConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Top)
    }
    
    public var bottomConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Bottom)
    }
    
    public var heightConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Height)
    }
    
    public var widthConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Width)
    }
    
}

func constraintForView(v:UIView, attribute:NSLayoutAttribute) -> NSLayoutConstraint? {
    if let spv = v.superview {
        for c in spv.constraints {
            if let fi = c.firstItem as? NSObject where fi == v && c.firstAttribute == attribute {
                return c
            }
            if let si = c.secondItem as? NSObject where si == v && c.secondAttribute == attribute {
                return c
            }
        }
    }
    return nil
}<commit_msg>height and width constraints are not on superview, rather the view themselves. Also added leading, trailing getters<commit_after>//
//  Stevia+GetConstraint.swift
//  Stevia
//
//  Created by <NAME> on 12/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public extension UIView {
    
    public var leftConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Left, existsOnView: self.superview)
    }
    
    public var rightConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Right, existsOnView: self.superview)
    }
    
    public var topConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Top, existsOnView: self.superview)
    }
    
    public var bottomConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Bottom, existsOnView: self.superview)
    }
    
    public var heightConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Height, existsOnView: self)
    }
    
    public var widthConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Width, existsOnView: self)
    }
    
    public var trailingConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Trailing, existsOnView: self.superview)
    }
    
    public var leadingConstraint:NSLayoutConstraint? {
        return constraintForView(self, attribute: .Leading, existsOnView: self.superview)
    }
    
}

func constraintForView(v:UIView, attribute:NSLayoutAttribute, existsOnView:UIView?) -> NSLayoutConstraint? {
    let target = existsOnView ?? v
    for c in target.constraints {
        if let fi = c.firstItem as? NSObject where fi == v && c.firstAttribute == attribute {
            return c
        }
        if let si = c.secondItem as? NSObject where si == v && c.secondAttribute == attribute {
            return c
        }
    }
    return nil
}
{'fraction_non_alphanumeric': 0.08779190067986994, 'fraction_numerical': 0.005911912503694945, 'mean_word_length': 2.7392265193370164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2887131', 'n_tokens_mistral': 937, 'n_tokens_neox': 915, 'n_words': 251}