Im very new to Objective-C and am currently learning how to use Xcode and create iOS applications. I am currently testing a Navigation based application. As part of my display I need to download web data, strip the html tags, format the string etc, which takes quite alot of code. I found when this code is inserted into the implementation file its quite slow in the iPhone simulator.
This may seem like a really obvious question but am I right putting the code in the View implementation file? or should I create a separate file to do all the data handling then pass the results to the view file?
Once again, sorry if this is trivial and any help is appreciated.
Im very new to Objective-C and am currently learning how to use Xcode and
Share
Hi and welcome to Stack Overflow! Technically, what you are doing now is fine. However, a common strategy for effective coding is called Model-View-Controller, where you separate components that do different things. For your example, the downloading and processing should take place in the model section, which is where content comes from. The controller is simply responsible for taking the model’s data and passing it to the view. The view is already provided as part of
UINavigationViewController. Again, this doesn’t affect performance, it’s just a style that makes later maintenance easier.EDIT
In response to your second question, here’s what you can do (assuming you have
MyModelandMyController).MyModel.h:MyModel.m:Then, in
MyController.m, initialize an instance ofMyModeland accessmodel.datawhenever you want that array.