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
@discardableResult | |
func example() -> String { | |
let description = "This is an example" | |
print(description) | |
return description | |
} |
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
func example() -> String { | |
let description = "This is an example" | |
print(description) | |
return description | |
} |
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
var value = example() | |
value.append(" with discardable") | |
print(value) |
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
let a = UIView() | |
let b = UIView() | |
a.topAnchor.constraint(equalTo: b.topAnchor) | |
let aBottom = a.bottomAnchor.constraint(equalTo: b.bottomAnchor) | |
aBottom.priority = .defaultHigh |
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
let containerView = UIView() | |
view.addSubview(containerView) |
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
let layoutGuide = UILayoutGuide() | |
view.addLayoutGuide(layoutGuide) |
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
[photoImageView, introLabel].forEach { self.view.addSubview($0) } |
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
NSLayoutConstraint.activate( | |
[ | |
layoutGuide.centerYAnchor.constraint(equalTo: view.centerYAnchor), | |
layoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
layoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
photoImageView.topAnchor.constraint(equalTo: layoutGuide.topAnchor), | |
photoImageView.centerXAnchor.constraint(equalTo: layoutGuide.centerXAnchor), | |
photoImageView.widthAnchor.constraint(equalTo: photoImageView.heightAnchor), | |
photoImageView.heightAnchor.constraint(equalToConstant: 250), |
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
// Subviews | |
let logoImageView = UIImageView() | |
let welcomeLabel = UILabel() | |
let dismissButton = UIButton() | |
// Add Subviews & Set view's translatesAutoresizingMaskIntoConstraints to false | |
[logoImageView, welcomeLabel, dismissButton].forEach { | |
self.addSubview($0) | |
$0.translatesAutoresizingMaskIntoConstraints = false | |
} |
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
extension UIView { | |
func addSubviewsUsingAutoLayout(_ views: UIView ...) { | |
views.forEach { | |
self.addSubview($0) | |
$0.translatesAutoresizingMaskIntoConstraints = false | |
} | |
} | |
} |
OlderNewer