Best practises, Fine tunning my SQL App,

Discussion in 'iOS Programming' started by mraheel, Aug 25, 2009.

  1. mraheel macrumors regular

    Apr 18, 2009
    Hi guys,
    Im really glad to say that my application framework and design is coming an end and the SQL data entries are beginning!..
    I have some questions regarding best practises and application performance.

    1] My application takes some time after getting tapped to show up.. I think theres a second of black view and then the tabbar app appears. The testing is being done in iPod device
    I dont really call much in AppDidfinishLaunching except
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
    	[window addSubview:tabBarController.view];
    //All arrays are synthesized.. and dealloc-ed
    	SList = [[NSMutableArray alloc] init];
    	sMap = [[NSMutableArray alloc] init];
    	SMList = [[NSMutableArray alloc] init];
    	ConditionsList = [[NSMutableArray alloc] init];
    c1=[[NSArray alloc] initWithObjects:@"item0", @"item1", @"item2",nil];
    //2 more similar NSArrays but with more NString data.
    	[window addSubview:tabBarController.view];
    	[self initialiseDatabaseCondition:@"SELECT ID FROM sList"];
    -(void)initialiseDatabaseCondition:(NSString *)sqline{
    	[ConditionsList removeAllObjects]; //This initialisation is executed multiple times.. so I clear the List everytime its called.
    	NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DB.sqlite"];
    	if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
    		const char *sqln = [sqline UTF8String];
            sqlite3_stmt *statement;
    		if (sqlite3_prepare_v2(database, sqln, -1, &statement, NULL) == SQLITE_OK) {			
                while (sqlite3_step(statement) == SQLITE_ROW) {
                    int pk = sqlite3_column_int(statement, 0);	
    				ConditionClass *nCon = [[ConditionClass alloc] initWithPrimaryKey:pk database:database];
    				[ConditionsList addObject:nCon];
    				[nCon release];
            NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    		//[self say:@"failed"];
    The initialiseDatabaseCondition grabs stuff from the SQLite db in a very exactly the same way as the example - SQLiteBooks. Any comments here.. to speeed up the process of loading would be great.

    I've seen some apps like (SQLiteBooks) that start with animation.. kinda,, like on tapping, the view appears with animation. In my case, the black view animates and shows up and then the tabbar view is added to it. How can i rectify/change this design flaw!??
    They've got a default.png...

    2]All arrays are in the AppDelegate. And I'm using them from all other controllers. Almost every controller's methods have this linkage. All tableView methods, pickerViews.. etc..
    	SDAppDelegate *appDel = (SDAppDelegate *)[[UIApplication sharedApplication]delegate];
    Should I localise the arrays to specific controllers if applicable/possible?

    3] I have a method, where I initialise the Database everytime depending on what the user chooses.. Like initialiseDatabaseWith@"Select ID from table WHERE site=";
    I kinda use NSString stringwithFormat method to attach the site=? to the string and call initialiseDatabase.. Since I'm calling it evertime the user chooses, As earliar you've seen in the code, I clearedAllObjects from that specific NSMutableArray.
    There isnt much memory handling here, since i know little about it..
    Is there a better way to save up memory and reload an array.. etc??

    4]SQL caching..? i dont know anything about it.. and direction is appreciated.

    5]I have about 4 tableviews, One requires checkmarks like -TouchCells, the other requires a subtext below the main text, another needs a disclosure indicator, etc..
    Due to my incredible laziness, i added booleans to my CustomCell and made a single Class to handle all 4 tableViews.

    	static NSString *kCustomCellID = @"MyCellID";
    	CustomCell *cell = (CustomCell *)[self.tableView dequeueReusableCellWithIdentifier:kCustomCellID];
    	if (cell == nil)
    		cell = (CustomCell *)[[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:kCustomCellID] autorelease];
    	cell.moreIndicatorNeeded = YES; //its the disclosureIndicator
    	cell.subtxtNeeded = YES;
    	SDAppDelegate *appDelegate = (SDAppDelegate *)[[UIApplication sharedApplication] delegate];
    	ConditionClass *nCon = (ConditionClass *)[appDelegate.ConditionsList objectAtIndex:indexPath.row];
    	cell.title = nCon.txtCondition;
    	cell.subtxt = [appDelegate.pp objectAtIndex:nCon.System];
    	return cell;
    This is an example of one! tableView... the other may say NO to those booleans

    6]Sometimes I feel im depending too much on my AppDelegate.. is it any real concern? But There had to be a common link between them!.. atleast for 2 mutablearrays that check and compare each other..

    and, if u still have some time for me :),

    HOW TOs: In my pickerView, i changed the Views. made its inside look great. with different fonts and different background colors..
    But theres one problem, The PickerView Color inside remains white. its only "pickerItems" change the background view to orange..or something
    THis is apparent on scroll.. when the data finishes, the white color appears.. So i concluded that since im slapping my view over it as pickerItems, thats happening,
    How can I change the Background white color of the pickerview entirely!.. IVE SEEN some apps that way
  2. boyplunder macrumors regular


    Sep 8, 2008
    That's a long entry!

    A minor point, maybe, but you refer to an initial black view when you open the app. This is likely because you do not have a default screen image. This is a graphic, which usually shows the initial screen list/view, or can be a 'startup' screen if the data takes a while to load. You might want to put a 'default.png' graphic in your bundle for this. You'll see a few of these in the example apps.

    Loading info from a SQLite database can be relatively slow, depending on the extent of data you load for each view. I'm dealing with lots of entries, but little actual text data, so things are pretty quick. I've also found custom list rows can slow things down a little when there is a lot to do in each row, so less is better in many cases.

    I have found that taking time to think about the structure of the data and any arrays will save a great deal of time later. It took me a few attempts to find the right structure for my first app.
  3. mraheel thread starter macrumors regular

    Apr 18, 2009
    Oh man, that's really long. I hope it's not a big violation.

    Yea that's what I thought. I was looking for a way to capture app and add that default.png.
  4. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Take a screenshot of your initial UI (either via the Organizer window or the device's built-in screenshot mechanism), rename the file Default.png, and add it to your application bundle (normally thrown into the Resources group).
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    If you're worried about parts of your app being slow then start by profiling with Shark. This can help you to find out where the time goes. It will help you to focus on those parts of the app that need to be optimized.
  6. mraheel thread starter macrumors regular

    Apr 18, 2009
    Yea, I don't think there is any other sdk easier than this! My concern about speed isn't much cuz the app loads pretty good. Instead of calling SQL in appdidfinishlaunching I used an activity indicator. And called it in run time. Basically gave the user a way to classify and call their choice

    Sometimes things get so easy in sdk that I question if my method is right.

    I'm more concerned if my method of clearing up the arrays is right in the code above within initialisedatabase is the right way to go. I'm getting so many mem leaks of nsstring. But I get them only once during right time at first load. And the app works flawlessly on the device.

    Please comment on the customcells issue if you can
    Thanks alot guys for replying

Share This Page