Skip to content

Commit

Permalink
add log function to control the console logs, for debugging & releasi…
Browse files Browse the repository at this point in the history
…ng mode
  • Loading branch information
keshavvishwkarma committed Sep 17, 2017
1 parent d2d3c64 commit 3dbdfc2
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 148 deletions.
28 changes: 22 additions & 6 deletions KVConstraintKit.xcodeproj/project.pbxproj
Expand Up @@ -84,12 +84,8 @@
isa = PBXGroup;
children = (
6BF09CCA1D58F67C0030699A /* KVConstraintKit.h */,
6BF09CE11D58F7410030699A /* KVConstraintKit.swift */,
6BF09CE91D58F9620030699A /* ApplyViewConstraint.swift */,
6BA7D2921D83EE4A004B3A91 /* KVConstraintKitProtocol.swift */,
6B4B394C1D62601B006AE3E4 /* KVConstraintKitOperators.swift */,
6BF09CEB1D58FC7A0030699A /* UIViewControllerExtension.swift */,
6BF09CE71D58F94C0030699A /* NSLayoutConstraintExtension.swift */,
6BFBB58D1F6F14EC009CE1FF /* Core */,
6BFBB58E1F6F1504009CE1FF /* Extensions */,
6BF09CCC1D58F67C0030699A /* Info.plist */,
);
path = KVConstraintKit;
Expand All @@ -104,6 +100,26 @@
path = KVConstraintKitTests;
sourceTree = "<group>";
};
6BFBB58D1F6F14EC009CE1FF /* Core */ = {
isa = PBXGroup;
children = (
6BF09CE11D58F7410030699A /* KVConstraintKit.swift */,
6BA7D2921D83EE4A004B3A91 /* KVConstraintKitProtocol.swift */,
6B4B394C1D62601B006AE3E4 /* KVConstraintKitOperators.swift */,
6BF09CE71D58F94C0030699A /* NSLayoutConstraintExtension.swift */,
);
name = Core;
sourceTree = "<group>";
};
6BFBB58E1F6F1504009CE1FF /* Extensions */ = {
isa = PBXGroup;
children = (
6BF09CE91D58F9620030699A /* ApplyViewConstraint.swift */,
6BF09CEB1D58FC7A0030699A /* UIViewControllerExtension.swift */,
);
name = Extensions;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down
12 changes: 7 additions & 5 deletions KVConstraintKit/ApplyViewConstraint.swift
Expand Up @@ -4,7 +4,7 @@
//
// Distributed under the MIT License.
//
// Copyright © 2016 Keshav Vishwkarma. All rights reserved.
// Copyright © 2016-2017 Keshav Vishwkarma <keshavvbe@gmail.com>. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -216,27 +216,29 @@ extension View
if !(inset.top.isFinite && inset.top.isNaN) {
(self +== .top).constant = inset.top
} else {
debugPrint("can not add inset.top because it does not have finite value")
log("can not add inset.top because it does not have finite value")
}

if !(inset.bottom.isFinite && inset.bottom.isNaN) {
(self +== .bottom).constant = inset.bottom
} else {
debugPrint("can not add inset.top because it does not have finite value")
log("can not add inset.top because it does not have finite value")
}

if !(inset.left.isFinite && inset.left.isNaN) {
(self +== .leading).constant = inset.left
} else {
debugPrint("can not add inset.top because it does not have finite value")
log("can not add inset.top because it does not have finite value")
}

if !(inset.right.isFinite && inset.right.isNaN) {
(self +== .trailing).constant = inset.right
} else {
debugPrint("can not add inset.top because it does not have finite value")
log("can not add inset.top because it does not have finite value")
}

}

}


2 changes: 1 addition & 1 deletion KVConstraintKit/KVConstraintKit.h
Expand Up @@ -4,7 +4,7 @@
//
// Distributed under the MIT License.
//
// Copyright © 2016 Keshav Vishwkarma. All rights reserved.
// Copyright © 2016-2017 Keshav Vishwkarma <keshavvbe@gmail.com>. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
31 changes: 12 additions & 19 deletions KVConstraintKit/KVConstraintKit.swift
Expand Up @@ -4,7 +4,7 @@
//
// Distributed under the MIT License.
//
// Copyright © 2016 Keshav Vishwkarma. All rights reserved.
// Copyright © 2016-2017 Keshav Vishwkarma <keshavvbe@gmail.com>. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -189,28 +189,27 @@ extension View
return accessAppliedConstraintBy(attribute: attr, attribute: attr, relation: relation)
}


public final func accessAppliedConstraintBy(attribute attr: NSLayoutAttribute, relation: NSLayoutRelation = .equal, completionHandler: @escaping (NSLayoutConstraint?) -> Void){
DispatchQueue.main.async { () -> Void in
completionHandler(self.accessAppliedConstraintBy(attribute: attr, relation: relation))
}
}

public final func accessAppliedConstraintBy(attribute attr: NSLayoutAttribute, attribute attr2: NSLayoutAttribute, relation: NSLayoutRelation = .equal)->NSLayoutConstraint? {
public final func accessAppliedConstraintBy(attribute attr1: NSLayoutAttribute, attribute attr2: NSLayoutAttribute, relation: NSLayoutRelation = .equal)->NSLayoutConstraint? {

// For Aspect Ratio
if ( attr == .width && attr2 == .height || attr == .height && attr2 == .width){
let c = View.prepareConstraint(self, attribute:attr, secondView:self, attribute:attr2, relation:relation)
if ( attr1 == .width && attr2 == .height || attr1 == .height && attr2 == .width){
let c = View.prepareConstraint(self, attribute:attr1, secondView:self, attribute:attr2, relation:relation)
let appliedConstraint = constraints.containsApplied(constraint: c!)
return appliedConstraint
} // For height & width
else if attr2 == .notAnAttribute && (attr == .width || attr == .height){
let c = View.prepareConstraint(self, attribute:attr, attribute:attr2, relation:relation)
else if attr2 == .notAnAttribute && (attr1 == .width || attr1 == .height){
let c = View.prepareConstraint(self, attribute:attr1, attribute:attr2, relation:relation)
let appliedConstraint = constraints.containsApplied(constraint: c!)
return appliedConstraint
}
else {
let c = prepareConstraintToSuperview(attribute: attr, attribute: attr2, relation: relation)
let c = prepareConstraintToSuperview(attribute: attr1, attribute: attr2, relation: relation)
let appliedConstraint = superview?.constraints.containsApplied(constraint: c!)
return appliedConstraint
}
Expand Down Expand Up @@ -240,14 +239,13 @@ extension View
setNeedsLayout()
}

public final func updateModifyConstraintsWithAnimation(_ completion:((Bool) -> Void)?)
{
public final func updateModifyConstraintsWithAnimation(_ completion:((Bool) -> Void)?) {
let duration = TimeInterval(UINavigationControllerHideShowBarDuration)
let referenceView = (superview != nil) ? superview! : self

UIView.animate(withDuration: duration, animations: { () -> Void in
referenceView.updateModifyConstraints()
}, completion: completion)
}, completion: completion)

}

Expand All @@ -269,24 +267,19 @@ extension View
accessAppliedConstraintBy(attribute: attribute)?.constant *= ratio
}


}

extension View
{
class final func prepareConstraint(_ firstView: View!, attribute attr1: NSLayoutAttribute, secondView: View?=nil, attribute attr2: NSLayoutAttribute = .notAnAttribute, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1, constant: CGFloat = 0) -> NSLayoutConstraint!{
// assert( (secondView != nil), "both firstView & secondView must not be nil.")

internal class final func prepareConstraint(_ firstView: View!, attribute attr1: NSLayoutAttribute, secondView: View?=nil, attribute attr2: NSLayoutAttribute = .notAnAttribute, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1, constant: CGFloat = 0) -> NSLayoutConstraint!{

assert(!multiplier.isInfinite, "Multiplier/Ratio of view must not be INFINITY.")
assert(!multiplier.isNaN, "Multiplier/Ratio of view must not be NaN.")

assert(!constant.isInfinite, "constant of view must not be INFINITY.")
assert(!constant.isNaN, "constant of view must not be NaN.")

// let preparePinConastrain : NSLayoutConstraint = NSLayoutConstraint(item: firstView, attribute: attr1, relatedBy: relation, toItem: secondView, attribute: attr2, multiplier: multiplier, constant: constant)
// return preparePinConastrain

return NSLayoutConstraint(item: firstView, attribute: attr1, relatedBy: relation, toItem: secondView, attribute: attr2, multiplier: multiplier, constant: constant)

}

}

0 comments on commit 3dbdfc2

Please sign in to comment.