Created
November 9, 2017 11:40
-
-
Save loromits/9a0f121282ebf01f68850cbcf4ab19ae to your computer and use it in GitHub Desktop.
Extend SnapKit with struct that is able to switch two sets of constraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SnapKit | |
struct ConstraintSwitcher { | |
private var initialActive = [Constraint]() | |
private var initialInactive = [Constraint]() | |
private(set) var isInitialActive = true | |
mutating func append(_ constraint: Constraint, active: Bool) { | |
if active == isInitialActive { | |
initialActive.append(constraint) | |
} else { | |
initialInactive.append(constraint) | |
} | |
} | |
mutating func switchInitial(active: Bool) { | |
if active { | |
initialActive.forEach { $0.deactivate() } | |
initialInactive.forEach { $0.activate() } | |
} else { | |
initialInactive.forEach { $0.deactivate() } | |
initialActive.forEach { $0.activate() } | |
} | |
isInitialActive = active | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment