Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-27-2009, 09: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
 

» Advertisements
» Stats
Members: 158,736
Threads: 89,190
Posts: 380,533
Top Poster: BrianSlick (7,129)
Welcome to our newest member, wrapsol
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.