How to use model objects instead of arrays and dictionaries?

Below is a simple example of how I read from plist and display the data in a table. If I used objects to represent my model, how would I do it?

@interface RootViewController : UITableViewController {
    NSMutableArray *namesArray;
}
@property (nonatomic, retain) NSMutableArray *namesArray;
@end


@implementation RootViewController
@synthesize namesArray;

- (void)viewDidLoad{
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"];

    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithContentsOfFile:path];

    self.namesArray = tempArray;

    [tempArray release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [namesArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [namesArray objectAtIndex:indexPath.row];
    return cell;
}

Can someone show me the correct way to build my model according to the MVC pattern for the above scenario? I assume that I am using singleton to return a set of Name objects . I basically want to find out the correct way to use model objects to represent my data.

+1
source share
2 answers

iOS MVC , () . Model, , . GUI.

, , .

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>
#import <Security/Security.h>


@interface Model : NSObject {
}
+(id)modelGetInstance;
+(NSData *)getRandomIV:(NSInteger)numBytes;
-(id)init;
-(NSString*)encrypt:(NSString*)plainText password:(NSString*)pw; // public
-(NSString*)decrypt:(NSString*)cipherText password:(NSString*)pw;  // public
@end

UNIX ENGINE-INTERFACE. MVC Smalltalk, MODEL ( ).

+1

plists MVC , . , Person:

NSMutableArray* tempArray = [[NSMutableArray alloc]initWithContentsOfFile:path];
NSMutableArray* people = [Person personArrayFromDictionaryArray:tempArray];

plist, .

NSMutableArray* arrayToStore = [Person dictionaryArrayFromPersonArray:people];

, .

+1

All Articles