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 09-11-2010, 03:47 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 67
Ajaxx is on a distinguished road
Default Problem with a warning for not declared

Code:
-(NSMutableArray *)readProperties {
	
	// For error information
	NSError *error;
	//Prepare File Manager
	NSString *filePath = [self dataFilePath];
	NSFileManager *fileMgr;
	fileMgr = [NSFileManager defaultManager];
	
	//Check from what module the call is coming from to ecide what to do
	if ([fileMgr fileExistsAtPath: filePath] == NO) {
		NSLog (@"File not found");
		//File does not exists, this is the first time the game starts
		//Set up default parameters
		NSString *fileString =@"0\n30\n30\n10\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n";
		// Write default parameters to file
		[fileString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
		NSArray *propertiesArray = [fileString componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings
		[fileString release];
	}
	else {		//File exists
		NSLog (@"File exists");
		NSString *fileString = [NSString stringWithContentsOfFile:filePath
																 encoding:NSUTF8StringEncoding
																	error:nil]; // reads file into memory as an NSString
		NSArray *propertiesArray = [fileString componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings
		[fileString release];
	}
	//>>>>Warning: 'propertiesArray undeclared'	
	NSMutableArray *propArray = [NSMutableArray addObjectsFromArray:propertiesArray];	
		
	return propArray;
}
Sorry for the newbie question but could someone nice please tell me why the propertiesArray is warned as undeclared?
Ajaxx is offline   Reply With Quote
Old 09-11-2010, 04:04 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

The two "propertiesArray" variables are declared inside a block (a compound statement surrounded by {} ), and they are not available outside of that block; each block has its own scope just like each function has its own scope. Variables declared inside a scope are not usually available outside that scope.

The fix in your case is to declare "propertiesArray" once, before the if statement. Then you can set it later.

PS - don't release fileString. You did not alloc, copy, retain, or "new" it, so you should not release it here.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 09-11-2010, 04:07 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 67
Ajaxx is on a distinguished road
Default

thanks, now i learned something here again :-)
Ajaxx 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: 343
13 members and 330 guests
bignoggins, carlandrews, cgokey, givensur, hzwegjxg, iGamesDev, jenniead38, linkmx, mraalex, PixelInteractive, raihan.zbr, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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