The problem
In unit tests I want to compare my two objects if they are equal, but for that I have to mark my struct with Equatable
protocol in the main app target which in fact is not requited in the main app.
I can't do
extension MyModel: Equatable {}
in test target as compiler gives the error Extension outside of file declaring struct 'MyModel' prevents automatic synthesis of '==' for protocol 'Equatable'
The solution
Allow test files to declare the Equatable
for main target models
I tested out the 3000 models with and without Equatable.
The average compile time taken by main file without Equatable is 5.5s
The average compile time taken by main file with Equatable is 20.82
So our main target can save lot of build time.
The size of the main binary without Equatable is 7,698,801 bytes
The size of the main binary without Equatable is 10,142,833 bytes
On an average 1000 models takes 1 MB of binary size.
The code I used to generate models is below, just moved all printed models in main file and run the test
let numberOfModels = 3000
for i in 1...numberOfModels {
print("struct My\(i)Model: Equatable {")
print(" let isEditable: Bool")
print(" let integer: Int")
print(" let double: Double")
print(" let string: String")
print(" let float: Float")
print("}\n")
}