OmerFlame / SwiftRant

devRant API library made in Swift.
GNU General Public License v3.0
3 stars 1 forks source link

put explicit initializers into extensions to keep default synthesized initializers #3

Closed WilhelmOks closed 2 years ago

WilhelmOks commented 2 years ago

Put the explicit initializers like init(from decoder: Decoder) into extensions of the structs, so that it doesn't prevent the generation of the default memberwise initializers. The default initializers are needed to easily create instances of the models for the purpose of mock or example data (e.g. for preview Views in SwiftUI).

OmerFlame commented 2 years ago

Looks alright! Merged.

WilhelmOks commented 2 years ago

I just realized that it doesn't work like intended because the synthesized initializer is internal access level and not usable from a project importing it as a module.

See this for more info: https://stackoverflow.com/questions/26224693/how-can-i-make-the-memberwise-initialiser-public-by-default-for-structs-in-swi

We could generate them from Xcode and mark public but that's really annoying.