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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-31-2010, 10:39 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default NSLog: displaying array content

Hi all,

I have an array which I know contains data (because the App works), but I need to examine the content.

If I write
Code:
NSLog(@"The contents of countries = %@",countries);
countries is the name of the array the out put is:

The contents of countries = <Countries: 0x72ae910>

Is there a reason why the actual data is not output and what does the "0x72ae910' represent.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-31-2010, 10:45 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Is countries just an array? Try [countries description]
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-31-2010, 10:51 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

tried that with the same output. Below is a part of the code"
Code:
countries = [[NSMutableArray alloc]init];
	
	sqlite3 *db = [iTravelv113AppDelegate getNewDBConnection];
	
	NSMutableString *query;

	query = [NSMutableString stringWithFormat:@"select * from countryList where countryName = '%@'", name];
	const char *sql =  [query UTF8String];
	sqlite3_stmt *compiledStatement = nil;
	
	if(sqlite3_prepare_v2(db, sql, -1, &compiledStatement, NULL) == SQLITE_OK) {
		// Loop through the results and add them to the feeds array
		while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
			// Read the data from the result row
			NSString *aName = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] autorelease];
			NSString *aCountry = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] autorelease];
			NSString *aCapital = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] autorelease];
			NSString *aLanguageF = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] autorelease];
			NSString *aLanguageS = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] autorelease];
			NSString *aVoltage = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] autorelease];
			NSString *aFreq = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] autorelease];
			NSString *aDialCode = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] autorelease];
			NSString *aCurrencyCode = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] autorelease];
			NSString *aCurrencyName = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] autorelease];
			NSString *aCurrencySymbol = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] autorelease];
			NSString *aPhonePolice = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] autorelease];
			NSString *aPhoneMedical = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] autorelease];
			NSString *aPhoneFire = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)] autorelease];
			NSString *aCountryFlag = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 15)] autorelease];
			NSString *aCountryKey = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)] autorelease];
			NSString *aCountryOutlet = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 16)] autorelease];
			NSString *atimeZone1 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 17)] autorelease];
			NSString *atimeZone2 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 18)] autorelease];
			NSString *atimeZone3 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 19)] autorelease];
			
			
			// Create a new country object with the data from the database
			Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
					firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
					currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
					phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
												  countryKey:aCountryKey countryOutletType:aCountryOutlet
													  timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
			// Add the country object to the countries Array
			[countries addObject:country];

			
			iTravelv113AppDelegate  *appDelegate = [[UIApplication sharedApplication] delegate];
			appDelegate.countriesList = countries;
			

			[country autorelease];

			NSLog(@"The contents of countries = %@",[countries description]);
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-31-2010, 10:57 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Do you have a "Countries" class? That log message confuses me.

Use properties.

I don't speak SQL, but I'm reasonably certain that none of those strings should be released.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-31-2010, 11:44 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

The .h and .m are below with some code removed because its too much for the post.
.h
Code:
@interface CountryTableViewController : UITableViewController  {

	CountryDetailViewController		*countryView;
	
	NSString *countryname;

	NSMutableArray *arrayOfCharacters;
	NSMutableDictionary *objectsForCharacters;
	
	
	// Array to store the country objects
	NSMutableArray *countries;
	
	// Database variables
	NSString *databaseName;
	NSString *databasePath;
	
}
@property (nonatomic, retain) IBOutlet CountryDetailViewController		*countryView;

@property (nonatomic, retain) NSMutableArray *countries;

@property (nonatomic, retain) NSString *countryname;
.m
Code:
@implementation CountryTableViewController
@synthesize countryView;
@synthesize countries;
@synthesize countryname;

-(void)initializeTableData
{

	arrayOfCharacters = [[NSMutableArray alloc]init];

	objectsForCharacters = [[NSMutableDictionary alloc]init];
	
	sqlite3 *db = [iTravelv113AppDelegate getNewDBConnection];
	for(char c='A';c<='Z';c++)
	{
		NSMutableString *query;
		
		query = [NSMutableString stringWithFormat:@"select countryName, countryFlag from countryList where countryName LIKE '%c%%'",c];
		
		const char *sql =  [query UTF8String];
		sqlite3_stmt *statement = nil;
		
		if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL)!=SQLITE_OK)

			NSAssert1(0,@"error preparing statement: '%s'", sqlite3_errmsg(db));
		else
			
		{
			NSMutableArray *arrayOfNames = [[NSMutableArray alloc]init];
			while(sqlite3_step(statement)==SQLITE_ROW)
				[arrayOfNames addObject:[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(statement, 0)]];
			
			if([arrayOfNames count] >0)
			{
				[arrayOfCharacters addObject:[NSString stringWithFormat:@"%c",c]];
				
				[objectsForCharacters setObject:arrayOfNames forKey:[NSString stringWithFormat:@"%c",c]];
			}
			[arrayOfNames release];
		}
	
sqlite3_finalize(statement);
}

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

	
	NSString *name = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

		
	if(self.countryView == nil) {
		CountryDetailViewController *viewController = [[CountryDetailViewController alloc] initWithNibName:@"CountryDetailViewController" bundle:nil];
		self.countryView = viewController;
		[viewController release];
		 [tableView deselectRowAtIndexPath:indexPath animated:YES];
	}
	
	countries = [[NSMutableArray alloc]init];
	
	sqlite3 *db = [iTravelv113AppDelegate getNewDBConnection];
	
	NSMutableString *query;

	query = [NSMutableString stringWithFormat:@"select * from countryList where countryName = '%@'", name];
	const char *sql =  [query UTF8String];
	sqlite3_stmt *compiledStatement = nil;
	
	if(sqlite3_prepare_v2(db, sql, -1, &compiledStatement, NULL) == SQLITE_OK) {
		// Loop through the results and add them to the feeds array
		while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
			// Read the data from the result row
			NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCountry = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCapital = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] ;
			NSString *aLanguageF = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] ;
			NSString *aLanguageS = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] ;
			NSString *aVoltage = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] ;
			NSString *aFreq = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] ;
			NSString *aDialCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] ;
			NSString *aCurrencyCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aCurrencyName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] ;
			NSString *aCurrencySymbol = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aPhonePolice = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] ;
			NSString *aPhoneMedical = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] ;
			NSString *aPhoneFire = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)] ;
			NSString *aCountryFlag = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 15)] ;
			NSString *aCountryKey = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)] ;
			NSString *aCountryOutlet = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 16)] ;
			NSString *atimeZone1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 17)] ;
			NSString *atimeZone2 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 18)] ;
			NSString *atimeZone3 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 19)];
			
			
			// Create a new country object with the data from the database
			Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
					firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
					currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
					phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
												  countryKey:aCountryKey countryOutletType:aCountryOutlet
													  timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
			// Add the country object to the countries Array
			[countries addObject:country];

			
			iTravelv113AppDelegate  *appDelegate = [[UIApplication sharedApplication] delegate];
			appDelegate.countriesList = countries;
			

			[country autorelease];

			NSLog(@"The contents of countries = %@",[countries description]);

	
	// Setup the animation
	[self.navigationController pushViewController:self.countryView animated:YES];
	// Set the title of the view to the countries name
	self.countryView.title = [country countryName];
	
	[self.countryView.countryName setText:[country countryName]];
	[self.countryView.capitalCity setText:[country capitalCity]];
	[self.countryView.firstLang setText:[country firstLang]];
	[self.countryView.secondLang setText:[country secondLang]];
	[self.countryView.currencyCode setText:[country currencyCode]];
	[self.countryView.currencyName setText:[country currencyName]];
	[self.countryView.voltage setText:[country voltage]];
	[self.countryView.freq setText:[country freq]];
	[self.countryView.phonePolice setText:[country phonePolice]];
	[self.countryView.phoneMedical setText:[country phoneMedical]];
	[self.countryView.phoneFire setText:[country phoneFire]];
	[self.countryView.dialCode setText:[country dialCode]];
	[self.countryView.countryOutletType setText:[country countryOutletType]];
	[self.countryView.timeZone1 setText:[country timeZone1]];
	[self.countryView.timeZone2 setText:[country timeZone2]];
	[self.countryView.timeZone3 setText:[country timeZone3]];
			
	[self.countryView setCountry:[country countryName]];
			
	
			
	UIImage *currencySymbol = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country currencySymbol] ofType:@"png"]];
	self.countryView.currencySymbol.image = currencySymbol;	
			[currencySymbol autorelease];
			
	UIImage *countryFlag = [[UIImage alloc]  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country countryFlag] ofType:@"gif"]];			
	self.countryView.countryFlag.image = countryFlag;
			[countryFlag autorelease];
	
	}
		
	}
	// Release the compiled statement from memory
	sqlite3_finalize(compiledStatement);

}
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-31-2010, 11:53 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok... So still not working then?

If you posted that in an attempt to show that you are using properties, then you need to go read the properties link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 12:31 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

I will spend some time reading your properties tutorial, I have already found some properties that are not been used and removed them.

Also changed the colour of "Project instant variable" to red which is making a lot easier to read my code.

Still not sure why I can read the content of the array but I am hoping that your tutorial will help.

Again many thanks for your time.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-01-2010, 10:01 AM   #8 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian and anyone else who reads this post.

Brian, I have read your tutorial a number of times and have learned a lot about "@property" and "@synthesize" along with how and when to release.

For this I thank you.

Having read all that I have I still can't figure out why may array is not displaying data form my NSLog statement. I must be missing something big, but what I do not know.

Could you please help with this and again point me to where you think I have an issue.

Again, many thanks for your time.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-01-2010, 11:34 AM   #9 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Oh, I don't know what the issue is yet. But the first step in troubleshooting is fixing obvious problems and seeing what turns up.

Post your updated code.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 12:04 PM   #10 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

The output from the NSLog is now:

2010-08-01 18:06:05.534 iTravelv113[3751:207] The contents of countries = (null)

I have declared my array in the .h

Code:
@interface CountryTableViewController : UITableViewController  {

	CountryDetailViewController		*countryView;
	
	NSString *countryname;

	NSMutableArray *arrayOfCharacters;
	NSMutableDictionary *objectsForCharacters;
	
	
	// Array to store the country objects
	NSMutableArray *countries;
	
	// Database variables
	NSString *databaseName;
	NSString *databasePath;
	
}
@property (nonatomic, retain) IBOutlet CountryDetailViewController		*countryView;
.m
Code:
@implementation CountryTableViewController
@synthesize countryView;
// code here which connects to SQL and calls a list of countries
//displays a table list and user taps a country.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

	
	NSString *name = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

		
	if(self.countryView == nil) {
		CountryDetailViewController *viewController = [[CountryDetailViewController alloc] initWithNibName:@"CountryDetailViewController" bundle:nil];
		self.countryView = viewController;
		[viewController release];
		 [tableView deselectRowAtIndexPath:indexPath animated:YES];
	}
	

	
	sqlite3 *db = [iTravelv113AppDelegate getNewDBConnection];
	
	NSMutableString *query;

	query = [NSMutableString stringWithFormat:@"select * from countryList where countryName = '%@'", name];
	const char *sql =  [query UTF8String];
	sqlite3_stmt *compiledStatement = nil;
	
	if(sqlite3_prepare_v2(db, sql, -1, &compiledStatement, NULL) == SQLITE_OK) {
		// Loop through the results and add them to the feeds array
		while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
			// Read the data from the result row
			NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCountry = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCapital = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] ;
			NSString *aLanguageF = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] ;
			NSString *aLanguageS = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] ;
			NSString *aVoltage = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] ;
			NSString *aFreq = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] ;
			NSString *aDialCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] ;
			NSString *aCurrencyCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aCurrencyName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] ;
			NSString *aCurrencySymbol = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aPhonePolice = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] ;
			NSString *aPhoneMedical = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] ;
			NSString *aPhoneFire = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)] ;
			NSString *aCountryFlag = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 15)] ;
			NSString *aCountryKey = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)] ;
			NSString *aCountryOutlet = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 16)] ;
			NSString *atimeZone1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 17)] ;
			NSString *atimeZone2 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 18)] ;
			NSString *atimeZone3 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 19)];
			
			
			// Create a new country object with the data from the database
			Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
					firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
					currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
					phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
												  countryKey:aCountryKey countryOutletType:aCountryOutlet
													  timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
			
			
			// Add the country object to the countries Array
			[countries addObject:country];
			
			
			NSLog(@"The contents of countries = %@",[countries  description]);

			

			[country autorelease];

			

	
	// Setup the animation
	[self.navigationController pushViewController:self.countryView animated:YES];
	// Set the title of the view to the countries name
	self.countryView.title = [country countryName];
	
	[self.countryView.countryName setText:[country countryName]];
	[self.countryView.capitalCity setText:[country capitalCity]];
	[self.countryView.firstLang setText:[country firstLang]];
	[self.countryView.secondLang setText:[country secondLang]];
	[self.countryView.currencyCode setText:[country currencyCode]];
	[self.countryView.currencyName setText:[country currencyName]];
	[self.countryView.voltage setText:[country voltage]];
	[self.countryView.freq setText:[country freq]];
	[self.countryView.phonePolice setText:[country phonePolice]];
	[self.countryView.phoneMedical setText:[country phoneMedical]];
	[self.countryView.phoneFire setText:[country phoneFire]];
	[self.countryView.dialCode setText:[country dialCode]];
	[self.countryView.countryOutletType setText:[country countryOutletType]];
	[self.countryView.timeZone1 setText:[country timeZone1]];
	[self.countryView.timeZone2 setText:[country timeZone2]];
	[self.countryView.timeZone3 setText:[country timeZone3]];
			
	[self.countryView setCountry:[country countryName]];
			
	
			
	UIImage *currencySymbol = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country currencySymbol] ofType:@"png"]];
	self.countryView.currencySymbol.image = currencySymbol;	
			[currencySymbol autorelease];
			
	UIImage *countryFlag = [[UIImage alloc]  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country countryFlag] ofType:@"gif"]];			
	self.countryView.countryFlag.image = countryFlag;
			[countryFlag autorelease];
	
	}
		
	}
	// Release the compiled statement from memory
	sqlite3_finalize(compiledStatement);

}

			

- (void)dealloc {
	[countryname			autorelease];
	[arrayOfCharacters		autorelease];
	[objectsForCharacters	autorelease];
	
    [super dealloc];
}
__________________
Many thanks, keep safe and well.



Dereck

Last edited by dcjones; 08-01-2010 at 12:06 PM.
dcjones is offline   Reply With Quote
Old 08-01-2010, 12:06 PM   #11 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, add that same log to more methods. Let's figure out if it is wrong the entire time, or if it changes.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 12:22 PM   #12 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,



I have created an NSLog for each of the statements within the SQL statement.
Code:
// Read the data from the result row
			NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCountry = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] ;
			NSString *aCapital = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] ;
			NSString *aLanguageF = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] ;
			NSString *aLanguageS = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] ;
			NSString *aVoltage = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] ;
			NSString *aFreq = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] ;
			NSString *aDialCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] ;
			NSString *aCurrencyCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aCurrencyName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] ;
			NSString *aCurrencySymbol = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] ;
			NSString *aPhonePolice = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] ;
			NSString *aPhoneMedical = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] ;
			NSString *aPhoneFire = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)] ;
			NSString *aCountryFlag = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 15)] ;
			NSString *aCountryKey = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)] ;
			NSString *aCountryOutlet = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 16)] ;
			NSString *atimeZone1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 17)] ;
			NSString *atimeZone2 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 18)] ;
			NSString *atimeZone3 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 19)];
			
			NSLog(@"The contents of NSString *aCountry = %@",[aCountry   description]);
			NSLog(@"The contents of NSString *aCapital = %@",[aCapital  description]);
			NSLog(@"The contents of NSString *aLanguageF = %@",[aLanguageF  description]);
			NSLog(@"The contents of NSString *aLanguageS = %@",[aLanguageS  description]);
			NSLog(@"The contents of NSString *aVoltage = %@",[aVoltage   description]);
			NSLog(@"The contents of NSString *aFreq = %@",[aFreq description]);
			NSLog(@"The contents of NSString *aDialCode = %@",[aDialCode  description]);
			NSLog(@"The contents of NSString *aCurrencyCode = %@",[aCurrencyCode  description]);
			NSLog(@"The contents of NSString *aCurrencyName = %@",[aCurrencyName  description]);
			NSLog(@"The contents of NSString *aCurrencySymbol = %@",[aCurrencySymbol  description]);
			NSLog(@"The contents of NSString *aPhonePolice = %@",[aPhonePolice  description]);
			NSLog(@"The contents of NSString *aPhoneMedical = %@",[aPhoneMedical  description]);
			NSLog(@"The contents of NSString *aPhoneFire = %@",[aPhoneFire  description]);
			NSLog(@"The contents of NSString *aCountryKey = %@",[aCountryKey  description]);
			NSLog(@"The contents of NSString *aCountryOutlet = %@",[aCountryOutlet  description]);
			NSLog(@"The contents of NSString *atimeZone1 = %@",[atimeZone1  description]);
			NSLog(@"The contents of NSString *atimeZone2 = %@",[atimeZone2  description]);
			NSLog(@"The contents of NSString *atimeZone3 = %@",[atimeZone3  description]);
and the output is:
Code:
2010-08-01 18:19:16.411 iTravelv113[3987:207] Database Successfully Opened  
2010-08-01 18:19:16.413 iTravelv113[3987:207] The contents of NSString *aCountry = Afghanistan 
2010-08-01 18:19:16.414 iTravelv113[3987:207] The contents of NSString *aCapital = Kabul
2010-08-01 18:19:16.414 iTravelv113[3987:207] The contents of NSString *aLanguageF = Afghan Persian or Dari
2010-08-01 18:19:16.415 iTravelv113[3987:207] The contents of NSString *aLanguageS = Pashtu
2010-08-01 18:19:16.416 iTravelv113[3987:207] The contents of NSString *aVoltage = 240 V
2010-08-01 18:19:16.417 iTravelv113[3987:207] The contents of NSString *aFreq = 50 Hz
2010-08-01 18:19:16.418 iTravelv113[3987:207] The contents of NSString *aDialCode = 93
2010-08-01 18:19:16.419 iTravelv113[3987:207] The contents of NSString *aCurrencyCode = AFN
2010-08-01 18:19:16.420 iTravelv113[3987:207] The contents of NSString *aCurrencyName = Afghanistan Afgani
2010-08-01 18:19:16.420 iTravelv113[3987:207] The contents of NSString *aCurrencySymbol = AFN
2010-08-01 18:19:16.422 iTravelv113[3987:207] The contents of NSString *aPhonePolice = 911
2010-08-01 18:19:16.422 iTravelv113[3987:207] The contents of NSString *aPhoneMedical = 100
2010-08-01 18:19:16.423 iTravelv113[3987:207] The contents of NSString *aPhoneFire = 911
2010-08-01 18:19:16.424 iTravelv113[3987:207] The contents of NSString *aCountryKey = A
2010-08-01 18:19:16.424 iTravelv113[3987:207] The contents of NSString *aCountryOutlet = C & F
2010-08-01 18:19:16.425 iTravelv113[3987:207] The contents of NSString *atimeZone1 = GMT + 4.30
2010-08-01 18:19:16.426 iTravelv113[3987:207] The contents of NSString *atimeZone2 = GMT
2010-08-01 18:19:16.426 iTravelv113[3987:207] The contents of NSString *atimeZone3 = GMT
2010-08-01 18:19:16.427 iTravelv113[3987:207] The contents of countries = (null)
Which is what I would expect.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-01-2010, 02:01 PM   #13 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, I just meant the log for the array should be placed in other methods. But regardless, you now have new information:

Code:
The contents of countries = (null)
This is different than your first post. This method suggests that the array doesn't actually exist. You need to build one somewhere.

Use a property for countries. Actually, use a property for everything you have in .h.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 02:44 PM   #14 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

I now have the .h file as:
Code:
@interface CountryTableViewController : UITableViewController  {

	CountryDetailViewController	*countryView;
	
	NSString *countryname;

	NSMutableArray *arrayOfCharacters;
	NSMutableDictionary *objectsForCharacters;
	
	
	// Array to store the country objects
	NSMutableArray *countries;
	
	// Database variables
	NSString *databaseName;
	NSString *databasePath;
	
}
@property (nonatomic, retain) IBOutlet CountryDetailViewController *countryView;
@property (nonatomic, retain) NSString *countryname;
@property (nonatomic, retain) NSMutableArray *arrayOfCharacters;
@property (nonatomic, retain) NSMutableDictionary *objectsForCharacters;
@property (nonatomic, retain) NSMutableArray *countries;
@property (nonatomic, retain) NSString *databaseName;
@property (nonatomic, retain) NSString *databasePath;
@end
I also have in the .m:
Code:
@synthesize countryView, countryname, arrayOfCharacters, objectsForCharacters, countries, databaseName, databasePath  ;
Also in the .m I now have:
Code:
countries = [[NSMutableArray alloc]init];
// Add the country object to the countries Array
[countries addObject:country];
NSLog(@"The contents of countries = %@",[countries  description]);
The output for the NSLog is:

2010-08-01 20:34:30.461 iTravelv113[4432:207] Database Successfully Opened
2010-08-01 20:34:30.464 iTravelv113[4432:207] The contents of NSString *aCountry = Afghanistan
2010-08-01 20:34:30.465 iTravelv113[4432:207] The contents of NSString *aCapital = Kabul
2010-08-01 20:34:30.466 iTravelv113[4432:207] The contents of NSString *aLanguageF = Afghan Persian or Dari
2010-08-01 20:34:30.466 iTravelv113[4432:207] The contents of NSString *aLanguageS = Pashtu
2010-08-01 20:34:30.467 iTravelv113[4432:207] The contents of NSString *aVoltage = 240 V
2010-08-01 20:34:30.469 iTravelv113[4432:207] The contents of NSString *aFreq = 50 Hz
2010-08-01 20:34:30.469 iTravelv113[4432:207] The contents of NSString *aDialCode = 93
2010-08-01 20:34:30.470 iTravelv113[4432:207] The contents of NSString *aCurrencyCode = AFN
2010-08-01 20:34:30.471 iTravelv113[4432:207] The contents of NSString *aCurrencyName = Afghanistan Afgani
2010-08-01 20:34:30.471 iTravelv113[4432:207] The contents of NSString *aCurrencySymbol = AFN
2010-08-01 20:34:30.472 iTravelv113[4432:207] The contents of NSString *aPhonePolice = 911
2010-08-01 20:34:30.472 iTravelv113[4432:207] The contents of NSString *aPhoneMedical = 100
2010-08-01 20:34:30.473 iTravelv113[4432:207] The contents of NSString *aPhoneFire = 911
2010-08-01 20:34:30.474 iTravelv113[4432:207] The contents of NSString *aCountryKey = A
2010-08-01 20:34:30.474 iTravelv113[4432:207] The contents of NSString *aCountryOutlet = C & F
2010-08-01 20:34:30.477 iTravelv113[4432:207] The contents of NSString *atimeZone1 = GMT + 4.30
2010-08-01 20:34:30.478 iTravelv113[4432:207] The contents of NSString *atimeZone2 = GMT
2010-08-01 20:34:30.478 iTravelv113[4432:207] The contents of NSString *atimeZone3 = GMT
2010-08-01 20:34:30.479 iTravelv113[4432:207] The contents of countryName = Afghanistan
2010-08-01 20:34:30.480 iTravelv113[4432:207] The contents of countries = (
"<Country: 0x7273190>"
)

Because of my inexperience with Objective-C, I am slowly losing the plot with this. All I am trying to do is capture the result of the SQL query and hold it in an array in the AppDelegate so I can call it from a number of different views.

Again, many thanks for all the time you have spent with this issue.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-01-2010, 02:57 PM   #15 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok, now we're getting somewhere.

You are not using your countries property. Reread the link in my signature. What you have works, but you are looking at a potential memory management problem.

Let me reformat this a bit and I think it will be clearer what you're seeing:
Code:
The contents of countries = 
(
   "<Country: 0x7273190>"
)
Your array contains a single Country object. I'm not certain about the specific meaning of the numbers, but I believe it is the memory address of that Country object. If this is what you've had all along, then it actually is correct. This is just slightly different from your original post, so if this IS what you've had all along, be sure to copy-paste stuff when posting.

Now, if you want better information from your Country object, then you will need to implement your own description method. Here is an example:

Code:
- (NSString *)description
{
   return [NSString stringWithFormat:@"\nCountry object has the following properties\n name: %@\n", [self name]];
}
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 02:58 PM   #16 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Switzerland
Age: 26
Posts: 35
Shod is on a distinguished road
Default

EDIT: BrianSlick was faster than me :P

Code:
2010-08-01 20:34:30.480 iTravelv113[4432:207] The contents of countries = (
"<Country: 0x7273190>"
)
this means your countries array contains 1 object if type Country, to show the "content" of the object Country in a friendly way you should add your own implementation of the - (NSString *)description method to the Country class.
That method would be something like:

Code:
- (NSString *)description {
    return [NSString stringWithFormat:@"[ country: %@  capital: %@ ...]", self.countryName, self.capital, ...];
}
Shod is offline   Reply With Quote
Old 08-01-2010, 04:23 PM   #17 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
dcjones is on a distinguished road
Default

Hi Brian,

well I have managed to populate my array by doing the following{
Code:
NSMutableArray *acountryList;
			
			acountryList = [NSMutableArray new];
			[acountryList addObject: aCountry];
			[acountryList addObject: aCapital];
			[acountryList addObject: aLanguageF];
			[acountryList addObject: aLanguageS];
			[acountryList addObject: aVoltage];
			[acountryList addObject: aFreq];
			[acountryList addObject: aDialCode];
			[acountryList addObject: aCurrencyCode];
			[acountryList addObject: aCurrencyName];
			[acountryList addObject: aCurrencySymbol];
			[acountryList addObject: aPhonePolice];
			[acountryList addObject: aPhoneMedical];
			[acountryList addObject: aPhoneFire];
			[acountryList addObject: aCountryFlag];
			[acountryList addObject: aCountryOutlet];
			[acountryList addObject: atimeZone1];
			[acountryList addObject: atimeZone2];
			[acountryList addObject: atimeZone3];
			
			
			NSLog(@"The contents of countries = %@",[acountryList  description]);
which now outputs:
Code:
2010-08-01 22:03:37.773 iTravelv113[5182:207] The contents of countries = (
    "Afghanistan ",
    Kabul,
    "Afghan Persian or Dari",
    Pashtu,
    "240 V",
    "50 Hz",
    93,
    AFN,
    "Afghanistan Afgani",
    AFN,
    911,
    100,
    911,
    Afghanistan,
    "C & F",
    "GMT + 4.30",
    GMT,
    GMT
)
All I need to do now is to write the array to the AppDelegate which hopefully I can call from any view in the app.

Brian, I would like to thank you very much for all your time you have spent trying to show me the way. My solution may not be a good way of doing it but it works. Many thanks.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 353
9 members and 344 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:16 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0