开发者

Problems passing NSString as argument in iPhone app

开发者 https://www.devze.com 2023-02-24 03:46 出处:网络
Here is the context of my problem. First there is a thread that gets started: -(void)run_thread: (NSObject* )file_path_NSObject

Here is the context of my problem. First there is a thread that gets started:

-(void)run_thread: (NSObject* )file_path_NSObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSStri开发者_JAVA百科ng *local_recordFilePath_NSString = (NSString *)file_path_NSObject;

NSLog(@"run thread : path   %@     ", local_recordFilePath_NSString);

printf("Running Thread...\n");

runAllAudioRoutines(local_recordFilePath_NSString);

// more code....

Everything above prints correctly to the console. Then there is the method that gets called:

void runAllAudioRoutines(NSString *file)

{

NSLog(@"running All Audio Routines method...\n");

NSString *truncatedFilePath = [file stringByReplacingOccurrencesOfString:@"LoopExtended.wav"
                                                                withString:@"recordedFile.wav"];

NSLog(@"FILE for  !!!! -->  %@",truncatedFilePath);

const char *location  = [truncatedFilePath UTF8String];
const char *write_location = [file UTF8String];

int *vocal_data = read_wav(location, &size_vocal); 

// more code....

The strange thing is that none of the NSLogs print at all. Nothing. Nada. Zip. And then the app crashes when it tries to pass the location to the read wav method (presumably because there is something wrong with the string).

This all started to happen when I switched from using NSTemporaryDirectory to NSBundle, but I'm not sure if that has anything to do with it. Any advice?

I've taken a Joetjah's suggestion and started using instead:

[self runAllAudioRoutines:local_recordFilePath_NSString];
     -(void)runAllAudioRoutines:(NSString*) file

and now I get this:

Problems passing NSString as argument in iPhone app

Second run with 2nd suggestion from Joetjah

Problems passing NSString as argument in iPhone app


The message you are getting says that SpeakHereController doesn't implement the method runAllAudioRoutines:.

Did you call runAllAudioRoutines: on the right object?

Expanding: Objective-C is a dynamic language. You can call any method on any object, but if the object doesn't implement the method, the app will crash, with the message:

"unrecognized selector sent to instance ..."

C++ is a static languages. If you try to call a function that isn't defined for an object, it won't compile. In Objective-C, it will compile, but you get the error during runtime. This is what's happening to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消