- How do we use protocols
- How to do it without protocols
- How to transform any protocol to a sturct
- Porotocol's limitations
- Struct oriented programming's limitations
- Play with uikit animations
protocol Animator {
associatedtype Target
static func animate(
_ target: Target,
completion: ((Bool) -> Void)?
)
}
struct FadeInAnimator: AnimatorProtocol {
static func animate(
_ target: UIView,
completion: ((Bool) -> Void)?
) {
UIView.animate(
withDuration: 5,
delay: 0,
options: [],
animations: { target.alpha = 0.0 },
completion: completion
)
}
}
struct Animator<Target> {
typealias Completion = (Bool) -> Void
var animate: (Target, _ completion: Completion?) -> Void
}
extension Animator where Target == UIView {
static func fadeOut(
params: UIViewAnimationParams
) -> Animator {
Animator { view, completion in
UIView.animate(
withDuration: params.duration,
delay: params.delay,
options: params.options,
animations: { view.alpha = 0.0 },
completion: completion
)
}
}
}
There are two main entites which you should look at:
Diffing - allows to compare Value
s and convert them to and from Data
Snapshotting - allows to transform a snapshottable value into a diffable format (like text or an image) for snapshot testing.
More about it: