Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

italiano40

macrumors 65816
Original poster
Oct 7, 2007
1,080
0
NY
this is my header file
Code:
#import <Cocoa/Cocoa.h>
#import <Foundation/NSTask.h>

@interface upload: NSObject{
    IBOutlet id afteruploadlabel;
    IBOutlet id iagreebutton;
    IBOutlet id ipaddresstextbox;
    IBOutlet id progressbar;
    IBOutlet id showimagelabel;
    IBOutlet id uploadbutton;
    NSString *fileName; 
}
- (IBAction)agree:(id)sender;
- (IBAction)upload:(id)sender;
@end

now in my .m file i use fileName in my two methods
but i get this error
error: 'fileName' undeclared (first use in this function)
what should i do?
 

italiano40

macrumors 65816
Original poster
Oct 7, 2007
1,080
0
NY
Mind posting your implementation file?

Did you import your .h file?

-Lee

yea i did import my .h file

here is the code that is flaging the error
i didn't include the second method
Code:
#import "upload.h"
#import "Foundation/NSTask.h"
@implementation NSObject

- (IBAction)agree:(id)sender { 
	int i; // Loop counter.
	
	// Create the File Open Dialog class.
	NSOpenPanel* openDlg = [NSOpenPanel openPanel];
	
	// Enable the selection of files in the dialog.
	[openDlg setCanChooseFiles:YES];
	
	// Enable the selection of directories in the dialog.
	[openDlg setCanChooseDirectories:YES];
	
	// Display the dialog.  If the OK button was pressed,
	// process the files.
	if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
	{
		// Get an array containing the full filenames of all
		// files and directories selected.
		NSArray* files = [openDlg filenames];
		
		// Loop through all the files and process them.
		for( i = 0; i < [files count]; i++ )
		{
			NSString* fileName = [files objectAtIndex:i];
			[uploadbutton hidden:false];
			[showimagelabel setStringValue: fileName];
		}
	}
	
}
//the second method is after this
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
This looks bad... you have:
Code:
NSString* fileName = [files objectAtIndex:i];
Masking your class member called fileName. Your new definition's scope is the for loop that it's in. I don't see anything that would point to where the error comes from, though.

Is the error in the function you posted or the second function? What line number is the error associated with?

Also, and this is just a point of style, I'd always put the * in a pointer declaration next to the variable and not the type. Syntactically either will work, but if you use a single line for multiple declarations it can be confusing, i.e.:
Code:
int* x,y;
x is an int pointer, y is an int. It might be obvious to some, but with int* there... it can be misleading.

-Lee
 

italiano40

macrumors 65816
Original poster
Oct 7, 2007
1,080
0
NY
Code:
#import "upload.h"
#import "Foundation/NSTask.h"
@implementation NSObject

- (IBAction)agree:(id)sender { 
	int i; // Loop counter.
	
	// Create the File Open Dialog class.
	NSOpenPanel* openDlg = [NSOpenPanel openPanel];
	
	// Enable the selection of files in the dialog.
	[openDlg setCanChooseFiles:YES];
	
	// Enable the selection of directories in the dialog.
	[openDlg setCanChooseDirectories:YES];
	
	// Display the dialog.  If the OK button was pressed,
	// process the files.
	if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
	{
		// Get an array containing the full filenames of all
		// files and directories selected.
		NSArray* files = [openDlg filenames];
		
		// Loop through all the files and process them.
		for( i = 0; i < [files count]; i++ )
		{
			NSString* fileName = [files objectAtIndex:i];//the error is here
			[uploadbutton hidden:false];
			[showimagelabel setStringValue: fileName];
		}
	}
	
}
//the second method is after this

i am just confused why my header file isn't working correct and it gives me an error that it hasn't been declare, when it has?
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
yea i did import my .h file

here is the code that is flaging the error
i didn't include the second method
Code:
#import "upload.h"
#import "Foundation/NSTask.h"
@implementation NSObject

You are trying to implement a method for class "NSObject". Class NSObject doesn't have a member named "filename", class "upload" does.

Also, it is very very bad style and really asking for trouble using the same name "upload" both for a class and for a member of that class. You are just going to confuse yourself.
 

cMacSW

macrumors regular
Mar 20, 2006
180
0
If you specify to create a class in xCode it will take care of having the right class names in the files for you.
 

cMacSW

macrumors regular
Mar 20, 2006
180
0
Also as gnasher729 said, you should consider your class names/properties more carefully. Ibelieve that Apple's dev site has a document about naming conventions.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.