/ Published in: Objective C
                    
                                        
Here's a simple object class that has been set up so it can be archived using the NSKeyedUnarchiver and NSKeyedArchiver classes. This process in another snippet.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/* INTERFACE */
#define kfavesArray @"favesArray"
#define kCurrentFave @"currentFave"
#define kCurrentFaveIndex @"currentFaveIndexPath"
#import <Foundation/Foundation.h>
@class FaveVO;
{
NSMutableArray *favesArray;
FaveVO *currentFave;
int faveIndex;
}
@property (nonatomic, retain) FaveVO *currentFave;
@property int faveIndex;
-(void)addNewFaveLocation:(FaveVO *)fave;
-(void)createNewFaveVOFromFaveVO:(FaveVO *)fave;
-(void)setFaveLocation:(int)index;
-(void)removeFaveLocation;
@end
/* IMPLEMENTATION */
#import "DataModel.h"
#import "FaveVO.h"
@implementation DataModel
@synthesize favesArray;
@synthesize currentFave;
@synthesize faveIndex;
//------------------------------------------------------
-(id)init
{
if(self = [super init])
{
}
return self;
}
//--------------------------------------------------
-(void)addNewFaveLocation:(FaveVO *)fave
{
[favesArray insertObject:fave atIndex:0];
currentFave = [favesArray objectAtIndex:0];
faveIndex = 0;
NSLog(@"DataModel currentFave: %@ faveIndex: %i", currentFave,faveIndex);
}
//--------------------------------------------------
-(void)setFaveLocation:(int)index
{
currentFave = [favesArray objectAtIndex:index];
faveIndex = index;
NSLog(@"DataModel currentFave: %@ faveIndex: %i", currentFave,faveIndex);
}
//--------------------------------------------------
-(void)removeFaveLocation
{
currentFave = nil;
NSLog(@"DataModel currentFave: %@ faveIndex: %i", currentFave,faveIndex);
}
//--------------------------------------------------
-(void)createNewFaveVOFromFaveVO:(FaveVO *)fave
{
double lat = fave.lat;
double lon = fave.lon;
lat:lat
lon:lon];
[favesArray addObject:newFaveVO];
[newFaveVO release];
}
//--------------------------------------------------
-(void)dealloc
{
[favesArray release];
[currentFave release];
[super dealloc];
}
//--------------------------------------------------
//--------------------------------------------------
#pragma mark NSCoding
{
[encoder encodeObject:favesArray forKey:kfavesArray];
[encoder encodeObject:currentFave forKey:kCurrentFave];
[encoder encodeInt:faveIndex forKey:kCurrentFaveIndex];
}
//--------------------------------------------------
{
NSLog(@"DataModel initWithCoder: %@", decoder);
if (self = [super init])
{
self.favesArray = [decoder decodeObjectForKey:kfavesArray];
self.faveIndex = [decoder decodeIntForKey:kCurrentFaveIndex];
self.currentFave = [favesArray objectAtIndex:faveIndex];
}
return self;
}
@end
Comments
 Subscribe to comments
                    Subscribe to comments
                
                