Study: Use type erasure to make CallPermissionsConfiguration Equatable
What's new in this PR?
Issues
(This is a study of type erasure not necessary to merge)
In CallInfoViewControllerInput, we wrote a isEqual method to compare 2 CallInfoViewControllerInput to act a s == method of Equatable. It works but:
- it is long
- easy to forgot update if new properties are added to the protocol
- 2 different object conforms
CallInfoViewControllerInputcan be equal (This protocol is written for MockingCallInfoConfiguration, so we need compare a mock and real object)
Causes
From the comment:
// Workaround to make the protocol equatable, it might be possible to conform CallInfoConfiguration
// to Equatable with Swift 4.1 and conditional conformances. Right now we would have to make
// the CallInfoRootViewController generic to work around the Self requirement of
// Equatable which we want to avoid.
With Swift 5 it is still not possible to make CallInfoViewControllerInput conforms Equatable due to same compiler error.
Solutions
Use type erasure to solve it. ref: https://khawerkhaliq.com/blog/swift-protocols-equatable-part-two/
- Conform
CallInfoConfigurationtoEquatable - It requires
CallInfoConfigurationmemberpermissions,mediaManagerandcallStatealsoEquatable. So we need to make them not a protocol type and conformsEquatable - Create
AnyCallPermissionsConfiguration,AnyAVSMediaManagerInterfaceandAnyCallStateExtendingas a wrapper of them - Add
isEqualmethod to above protocol, and add default implementation to the extensions (where Self: Equatable)
Discuss
- [ ] Is it worth to apply the change? These protocols are only conformed by 2 struct/class and one of them is Mock.