Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-27-2009, 08:54 PM   #25 (permalink)
exorcyze
Registered Member
 
Join Date: Dec 2008
Posts: 495
Default

Well it's nothing terribly magical, and I'll assume that anyone reading this can parse out the header vs module code and that stubs of course have code in them, but maybe this will help the idea:

In app delegate, I have a property to access the data manager class instance:
Code:
// header
@class DataManager;
@interface myAppDelegate : NSObject <UIApplicationDelegate> {
	UIWindow *window;
	UINavigationController *navigationController;
	DataManager *manager;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) DataManager *manager;
@end

// module

@synthesize manager;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
	// initialize our data manager
	DataManager *myManager = [[DataManager alloc] init];
	self.manager = myManager;
	[myManager release];
	
	// Configure and show the window
	navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}
- (void)dealloc {
	[manager release];
	[navigationController release];
	[window release];
	[super dealloc];
}
Header for the DataManager class
Code:
#import <Foundation/Foundation.h>

#define kDatabaseName @"mydatabase.sqlite"

@class FMDatabase;
@class Foo;
@class Bar;

@interface DataManager : NSObject {
	FMDatabase *database;
	NSAutoreleasePool *pool;
	
	NSMutableArray *foos;
	NSMutableArray *bars;	
}

@property (nonatomic, retain) NSMutableArray *foos;
@property (nonatomic, retain) NSMutableArray *bars;

- (void) getFoos;
- (NSInteger) addFoo:(Foo *)myfoo;
- (void) updateFoo:(Foo *)myfoo;
- (void) deleteFoo:(Foo *)myfoo;

- (void) getBarsForFoo:(int)fooid;
- (NSInteger) addBar:(Bar *)mybar;
// etc...

@end
Like I said, nothing super magical here, but it at least consolidates my data access code and the data points that need to be shared in the application without cluttering the delegate. To access data from somewhere I can get at one of the data points using something like the following:
Code:
MyAppDelegate *delegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
DataManager *manager = delegate.manager;
Foo *iPityTha = (Foo *)[manager.foos getObjectAtIndex:2];
This has seemed to work decently well for me, but I'm open to any suggestions for improvement. =)
__________________
My Apps on AppStore : gScale (guitar scales reference), eMaze, eMaze Lite, eTimesheet
exorcyze is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,873
Threads: 38,649
Posts: 169,647
Top Poster: smasher (2,547)
Welcome to our newest member, JBTech
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:26 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.