I know in python it is good practice to have a models.py and put all of an application's model classes in there. Does the same apply to swift or is it better to have a separate file for each model class?
Thanks!
I know in python it is good practice to have a models.py and put all of an application's model classes in there. Does the same apply to swift or is it better to have a separate file for each model class?
Thanks!
Apple recommends to have separate files for each model class however it's possible to use the "Python style"
There is no single correct answer to this question, but Swift's system of controlling access suggests that it is not the best practice.
Properties and methods marked
private
are only visible within the same source file. If you put all of your model classes into a single file, they will all have access to each others'private
methods and properties, which defeats the whole purpose of marking somethingprivate
.Assuming that your project is average..I would put each of your models in a separate file. Sometimes you end up with some small files, but I would rather go through that then some massive file where I can't find anything.