Merge pull request #71 from Reflejo/cosmetics-changes-swift-1.2

Simplifications and swift 1.2 syntax
This commit is contained in:
Robert Payne 2015-04-11 17:07:51 +12:00
commit a31df70146
3 changed files with 11 additions and 21 deletions

View File

@ -313,7 +313,7 @@ public class Constraint {
NSException(name: "Cannot Install Constraint", reason: "Already installed on different view.", userInfo: nil).raise() NSException(name: "Cannot Install Constraint", reason: "Already installed on different view.", userInfo: nil).raise()
return [] return []
} }
return (self.installedLayoutConstraints?.allObjects as? Array<LayoutConstraint>)! return self.installedLayoutConstraints?.allObjects as! Array<LayoutConstraint>
} }
var newLayoutConstraints = Array<LayoutConstraint>() var newLayoutConstraints = Array<LayoutConstraint>()
@ -465,9 +465,9 @@ public class Constraint {
private func constrainTo(other: ConstraintItem, relation: ConstraintRelation) -> Constraint { private func constrainTo(other: ConstraintItem, relation: ConstraintRelation) -> Constraint {
if other.attributes != ConstraintAttributes.None { if other.attributes != ConstraintAttributes.None {
var toLayoutAttributes = other.attributes.layoutAttributes let toLayoutAttributes = other.attributes.layoutAttributes
if toLayoutAttributes.count > 1 { if toLayoutAttributes.count > 1 {
var fromLayoutAttributes = self.fromItem.attributes.layoutAttributes let fromLayoutAttributes = self.fromItem.attributes.layoutAttributes
if toLayoutAttributes != fromLayoutAttributes { if toLayoutAttributes != fromLayoutAttributes {
NSException(name: "Invalid Constraint", reason: "Cannot constrain to multiple non identical attributes", userInfo: nil).raise() NSException(name: "Invalid Constraint", reason: "Cannot constrain to multiple non identical attributes", userInfo: nil).raise()
return self return self
@ -509,22 +509,22 @@ public class Constraint {
} }
private class func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? { private class func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? {
var views = NSMutableSet() var views = Set<View>()
var fromView = fromView var fromView = fromView
var toView = toView var toView = toView
do { do {
if let view = toView { if let view = toView {
if views.containsObject(view) { if views.contains(view) {
return view return view
} }
views.addObject(view) views.insert(view)
toView = view.superview toView = view.superview
} }
if let view = fromView { if let view = fromView {
if views.containsObject(view) { if views.contains(view) {
return view return view
} }
views.addObject(view) views.insert(view)
fromView = view.superview fromView = view.superview
} }
} while (fromView != nil || toView != nil) } while (fromView != nil || toView != nil)

View File

@ -41,22 +41,12 @@ public class ConstraintItem {
internal var attributes: ConstraintAttributes internal var attributes: ConstraintAttributes
internal var view: View? { internal var view: View? {
get { return self.object as? View
if let view = self.object as? View {
return view
}
return nil
}
} }
#if os(iOS) #if os(iOS)
internal var layoutSupport: UILayoutSupport? { internal var layoutSupport: UILayoutSupport? {
get { return self.object as? UILayoutSupport
if let layoutSupport = self.object as? UILayoutSupport {
return layoutSupport
}
return nil
}
} }
#endif #endif
} }

View File

@ -95,7 +95,7 @@ public extension View {
if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? Array<LayoutConstraint> { if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? Array<LayoutConstraint> {
return constraints return constraints
} }
return Array<LayoutConstraint>() return []
} }
set { set {
objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC)) objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))