Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save boyvanamstel/e01e689dd141d3d97d202007e9bacd2d to your computer and use it in GitHub Desktop.
Save boyvanamstel/e01e689dd141d3d97d202007e9bacd2d to your computer and use it in GitHub Desktop.
extension NSDirectionalEdgeInsets {
/// Returns new insets with just a value applied to the supplied edge.
///
/// - Parameters:
/// - edge: The edge to apply an inset to.
/// - value: The value to set the edge inset to.
init(_ edge: WritableKeyPath<Self, CGFloat>, _ value: CGFloat) {
self.init(
top: edge == \.top ? value : 0.0,
leading: edge == \.leading ? value: 0.0,
bottom: edge == \.bottom ? value : 0.0,
trailing: edge == \.trailing ? value : 0.0
)
}
}
let bottomInsets = NSDirectionalEdgeInsets(\.bottom, 200.0)
print(bottomInsets) // NSDirectionalEdgeInsets(top: 0.0, leading: 0.0, bottom: 200.0, trailing: 0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment