Defining a Publisher
pipeline, that Never
fails:
Before
let diamonds: AnyPublisher<Diamond, Never>
After
let diamonds: Flow<Diamond>
Type-erasing a Never
failing Publisher
pipeline to AnyPublisher
:
Before
let diamonds: AnyPublisher<Diamond, Never> =
Just(Diamond(carat: 7))
.eraseToAnyPublisher()
After
let diamonds: Flow<Diamond> =
Just(Diamond(carat: 7))
.eraseToFlow()
Edit newly created entities right where they are defined...
Before
final class DiamondView: UIView {
@UsesAutoLayout private var titleLabel = UILabel(style: .title2)
// MARK: Initializer
override init(frame: CGRect = .zero) {
super.init(frame: frame)
setupViews()
}
// MARK: Private
private func setupViews() {
titleLabel.textAlignment = .center
titleLabel.allowsDefaultTighteningForTruncation = true
titleLabel.adjustsFontSizeToFitWidth = true
titleLabel.minimumScaleFactor = 0.5
}
}
After
final class DiamondView: UIView {
@UsesAutoLayout private var titleLabel = UILabel(style: .title2).then {
$0.textAlignment = .center
$0.allowsDefaultTighteningForTruncation = true
$0.adjustsFontSizeToFitWidth = true
$0.minimumScaleFactor = 0.5
}
// MARK: Initializer
override init(frame: CGRect = .zero) {
super.init(frame: frame)
}
}
Replace "helper" properties with in-place-setup:
Before
private var buttonConstraint: NSLayoutConstraint?
private func setupConstraints() {
buttonConstraint = heightAnchor.constraint(equalToConstant: 16)
buttonConstraint?.priority = .defaultHigh
buttonConstraint?.isActive = true
NSLayoutConstraint.activate([
// other constraint setup ..
])
}
After
private func setupConstraints() {
NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: 16).then {
$0.priority = .defaultLow
},
// other constraint setup ..
])
}