Javier Cicchelli 9bcdaa697b [Setup] Basic project structure (#1)
This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended.

To summarise this work:
- [x] created a new **Xcode** project;
- [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project;
- [x] created the `Locations` app and also, its `Libraries` package;
- [x] created the `Shared` package to share dependencies between the apps;
- [x] added a `Makefile` file and implemented some **environment** and **help** commands.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#1
2023-04-08 18:37:13 +00:00

40 lines
2.1 KiB
Swift

import UIKit
@objc public extension UIView {
func addCenteredSubview(_ subview: UIView) {
addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
let centerXConstraint = centerXAnchor.constraint(equalTo: subview.centerXAnchor)
let centerYConstraint = centerYAnchor.constraint(equalTo: subview.centerYAnchor)
NSLayoutConstraint.activate([centerXConstraint, centerYConstraint])
}
@objc func wmf_addSubviewWithConstraintsToEdges(_ subview: UIView) {
wmf_addSubview(subview, withConstraintsToEdgesWithInsets: .zero)
}
@objc func wmf_addSubview(_ subview: UIView, withConstraintsToEdgesWithInsets insets: UIEdgeInsets, priority: UILayoutPriority = .required, belowSubview: UIView? = nil) {
if let belowSubview = belowSubview {
insertSubview(subview, belowSubview: belowSubview)
} else {
addSubview(subview)
}
wmf_addConstraintsToEdgesOfView(subview, withInsets: insets, priority: priority)
}
// Until we drop iOS 10 and can use NSDirectionalEdgeInsets, assume insets.left == leading & insets.right == trailing
@objc func wmf_addConstraintsToEdgesOfView(_ subview: UIView, withInsets insets: UIEdgeInsets = .zero, priority: UILayoutPriority = .required) {
subview.translatesAutoresizingMaskIntoConstraints = false
subview.frame = bounds.inset(by: insets)
let topConstraint = subview.topAnchor.constraint(equalTo: topAnchor, constant: insets.top)
topConstraint.priority = priority
let bottomConstraint = bottomAnchor.constraint(equalTo: subview.bottomAnchor, constant: insets.bottom)
bottomConstraint.priority = priority
let leftConstraint = subview.leadingAnchor.constraint(equalTo: leadingAnchor, constant: insets.left)
leftConstraint.priority = priority
let rightConstraint = trailingAnchor.constraint(equalTo: subview.trailingAnchor, constant: insets.right)
rightConstraint.priority = priority
addConstraints([topConstraint, bottomConstraint, leftConstraint, rightConstraint])
}
}