I work on a notepad website part-time, following the steps in iOS apps. Last week I got my first Mac and put together half the working application. Now, having convinced myself of this SO answer , I restart the attempt to learn MVC. I am on a very steep learning curve, so please bear with me.
I read MVC, separating the layers, three boxes and a few arrows, I understood. However, translating theory into the real world is frustrating. Most of the applications I've been looking at don't seem to use MVC. Even this Apple LazyTableImages example seems to use app delegateas a model that bothers me. I built on this a perfectly simple MVC example .
My application retrieves location markers from a web service. I have a tabbed application using ARC. On one tab, there is a Mapkit map for displaying markers.
A simple class for storing marker entries:
@interface MarkerRecord : NSObject
@property (strong, nonatomic) NSDecimalNumber *lat;
@property (strong, nonatomic) NSDecimalNumber *lon;
@property (strong, nonatomic) NSString *des;
A model class containing a set of marker classes for serving both views. This is my Model.h class:
@interface MarkersModel : NSObject
- (void)getMarkers;
- (void)postMarker;
And implementation:
@interface MarkersModel ()
@property (strong, nonatomic) NSArray *data;
@end
@implementation MarkersModel
@synthesize data;
- (void)getMarkers
{
...
}
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
data = objects;
}
Class mapViewController.h:
#import <MapKit/MapKit.h>
#import "MarkersModel.h"
@interface MapViewController : UIViewController<MKMapViewDelegate> {
MarkersModel *markersModel;
}
@property (nonatomic, strong) IBOutlet MKMapView *mapView;
@end
And implementation:
@interface MapViewController ()
@end
@implementation MapViewController
- (void)viewDidLoad
{
[super viewDidLoad];
markersModel = [[MarkersModel alloc] init];
}
-(void)viewWillAppear:(BOOL)animated
{
[markersModel getMarkers];
}
- (void)putMarkersOnMap
{
...
}
Here is my main question:
- Is my code above (start) worthy of an MVC implementation?
If yes:
- How to get the model for updating the controller (for example, how do I get the MarkersModel.objectLoader function to call mapViewController.putMarkersOnMap)?
I strongly suspect that the answer is a user delegate on the controller, but I can’t see for life how to implement it. I cannot relate any examples to my situation. I think I need something like this on the controller:
@class MapViewController;
@protocol MapViewControllerDelegate;
:
- - - , -
unsafe_unretained ( 4.3)? - MarkersModel ? , ARC . , , .
- MarkersModel.getMarkers ?
, . , .