i’m trying to create a clear MVC model where the Controller is the only one with access to the view and the model, so the model does not know of the view and vice versa.
I have created my model in a seperate xcode project, tested it and it does what it has to do. Now i was thinking in stead of just copying the code to a new ‘complete application’ project with the controller and the view, is it maybe a better idea to just create a library for the model, and let the controller work with that?
As i love to keep the views and model ‘dumb’, i don’t see any issue, my controller just handles all communication.
Is there a clear do or don’t advice here? I have no clean benefit of extracting the model to a library (not gonna reuse it soon), but it just seemed more clean to have my model in a separate project and just import it as a library in my application, for my controller to access.
I have heard of ‘including other projects’ in your new xcode project, so maybe thats another way to keep my model in a seperate project and keep it working in the full application?
Just searching for the best way to approach the separation of my model and the controller.
Thanks!
Setup your new ‘complete application’ project, then in the navigator right click and choose
New Group, call this groupModelEngineand insert the modelEngine source files to the project. It will look similar to the image below.Under BuildPhase tab you see that the ModelEngine is compiled together with the
complete appeven so the file are locate inside the other project. (Not sure how big your modelEngine its, but I would expect a small overhead at compile time, if at all)Do not select
copy files if needed(I think that what its called) because you want to have only one instance of your model engine files. Otherwise it could become confusing to understand which file is part of which project.The
complete appcan now #import the ModelEngine.h file. If needed, you can still run the Model Project as a separate app. If you make changes to the model they are immediately reflected also in the ModelEngine project.HTH