Reputation: 6190
A typical iOS application is developed using the MVC pattern. If I have extra classes that contain pure logic, like
These classes are neither controllers, nor models, nor view. They provide functional services. How do they fit into this MVC stuff?
Upvotes: 0
Views: 250
Reputation: 125007
Any of the three categories (model, view, controller) are free to use other classes that may not strictly fit into one of those roles.
A model object might use AES to encrypt and decrypt stored data, for example, and it might store the encryption key in the keychain. A controller might use the keychain to limit access to certain portions of an app. A view might use a class that implements FFT to help it partition data for display.
MVC is a paradigm for designing applications, but it's not a complete list of the allowable classes. Cocoa and Cocoa Touch themselves are full of classes that may be used by model, view, and/or controller classes, but which don't fit into those roles themselves. Consider all the container classes (NSArray, NSSet, NSDictionary, etc.), value classes (NSNumber, NSString, etc.), classes representing different parts of the operating system (NSFileManager, NSUserDefaults, and other things that I won't try to categorize like UITouch, NSEvent, NSJSONSerialization, and so on. I haven't counted, but I'd guess that the Cocoa and Cocoa Touch classes that don't fit into one of the three MVC roles far outnumber those that do.
Upvotes: 1
Reputation: 53850
If they're helper classes, then as others have pointed out, they're part of the C in MVC.
Unless, of course they're part of the model. If they model the data, or business requirements of your application, then they are part of the M in MVC.
Regardless, inside your controllers, you'll simply use an import statement and use the classes as needed. You'll instantiate the classes, call instance methods, call class methods, store instances as properties, etc.
Quite often, you'll find yourself using the singleton pattern similar to [NSUserDefaults standardUserDefaults]
.
Upvotes: 1
Reputation: 5190
As all those classes are performing actions, they could be considered as Helper methods, or utility methods. No matter what you call them, they are still Controllers, as Antonio MG pointed out.
For instance, I typically have the following Controllers in my classes:
I label them Controllers, and put them in a Controllers folder in my Xcode project.
Upvotes: 1
Reputation: 20410
Those libraries/classes are part of the controller, because it uses them to make its function.
For example, the controller connects to a webserver and display to the view, that's part of the controller job, or uses some library to encrypt some data before sending it to the model.
Upvotes: 1