Mac simple trouble with XCode Obj-C method definition

Oats

macrumors regular
Original poster
Jan 8, 2003
192
1
New York
I am relatively new to Objective-C and XCODE. I know C++ very well, but objective-C is giving me some headaches so far. I am trying to define a simple class, with one method / function which has two parameters, searchStr and searchPath. However, when I try to use this method, I get an error that indicates that the method could not be found or called.

Here is my search.h file:
PHP:
#import <Cocoa/Cocoa.h>

@interface CSearch : NSObject
    - (NSMutableArray *) searchForFiles:(NSString *)searchStr path:(NSString *)searchPath;

@end
here is the search.m file:
PHP:
#import "Search.h"

@implementation CSearch

- (id) init { return self; }

- (void) dealloc { [super dealloc]; }

//
// SEARCH FOR FILES
//////////////////////////////////////////////////////
- (NSMutableArray *) searchForFiles:(NSString *)searchStr path:(NSString *)searchPath
{
    ...
}

@end
and finally, here is the portion of code where my function is called:
PHP:
	CSearch  * searchClass;
	NSString *searchStr = @"searchstring";
	NSString *filePathSearchStr = @"testpath";
	[searchClass searchForFiles:searchStr path:filePathSearchStr];
The project compiles with no warnings or errors, but when I try to call the searchForFiles method, it can't be found or hangs in debug mode. Any idea what I am doing wrong?
Thanks!!
 

iSee

macrumors 68040
Oct 25, 2004
3,525
253
Yeah, searchClass is not initialized in the last code block.
You need to do something like this for the first line:
Code:
CSearch  * searchClass = [[CSearch alloc] init];
Your current code is equivalent to:
Code:
   CSearch  * searchClass;
    char searchStr[] = "searchstring"; 
    char filePathSearchStr[] = "testpath"; 
   searchClass->searchForFiles(searchStr, filePathSearchStr);
in C++
 

Oats

macrumors regular
Original poster
Jan 8, 2003
192
1
New York
Yeah, searchClass is not initialized in the last code block.
You need to do something like this for the first line:
Code:
CSearch  * searchClass = [[CSearch alloc] init];
indeed you are correct. thanks so much!!