Struct oriented programming vs Protocol oriented programming
- 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 oriented programming
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?($0) }
)
}
}
Struct oriented programming
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?($0) }
)
}
}
}
Where does it use?
SnapshotTesting
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:
- Protocol Witnesses: Part 1
- Protocol Witnesses: Part 2
- Advanced Protocol Witnesses: Part 1
- Advanced Protocol Witnesses: Part 2
- Protocol-Oriented Library Design: Part 1
- Protocol-Oriented Library Design: Part 2
- Witness-Oriented Library Design
- Async Functional Refactoring