-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PimCoumans/feature/improved-generics
Improved generics
- Loading branch information
Showing
4 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
#if canImport(AppKit) | ||
import AppKit | ||
|
||
extension NSView: ViewConstraintBuildable { | ||
public func withSuperview(_ method: (NSView) -> Void) { | ||
extension ViewConstraintBuildable where Self: NSView { | ||
public func withSuperview(_ method: (LayoutContainerView) -> Void) { | ||
guard let superview else { | ||
return assertionFailure() | ||
} | ||
method(superview) | ||
} | ||
|
||
public func applyConstraints(@ConstraintBuilder _ builder: (NSView) -> [NSLayoutConstraint]) { | ||
public func applyConstraints(@ConstraintBuilder _ builder: (Self) -> [NSLayoutConstraint]) { | ||
translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate(builder(self)) | ||
} | ||
} | ||
extension NSView: ViewConstraintBuildable { } | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
#if canImport(UIKit) | ||
import UIKit | ||
|
||
extension UIView: ViewConstraintBuildable { | ||
public func withSuperview(_ method: (UIView) -> Void) { | ||
extension ViewConstraintBuildable where Self: UIView { | ||
public func withSuperview(_ method: (LayoutContainerView) -> Void) { | ||
guard let superview else { | ||
return assertionFailure() | ||
} | ||
method(superview) | ||
} | ||
|
||
public func applyConstraints(@ConstraintBuilder _ builder: (UIView) -> [NSLayoutConstraint]) { | ||
public func applyConstraints(@ConstraintBuilder _ builder: (Self) -> [NSLayoutConstraint]) { | ||
translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate(builder(self)) | ||
} | ||
} | ||
extension UIView: ViewConstraintBuildable { } | ||
#endif |
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