0

i would like to create a function called "playSound" with one (but later two parameters - one, which is the filename and one, which is the musictype (mp3,...))

but i cant get the paramter working in my function...please help me

here's my code

 // // MainView.m // // Created by Christopher Fuchs on 26.01.11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "MainView.h" #import <AVFoundation/AVAudioPlayer.h> #import <AVFoundation/AVFoundation.h> @implementation MainView void playSound(char filename){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mein Alert" message:filename delegate:nil cancelButtonTitle:@"Abbrechen" otherButtonTitles:nil]; [alert show]; [alert release]; } - (IBAction)PlayFatGuyWalking:(id)sender { playSound(@"MusicFile"); } @end 

For now, i just added an alert instead of the playing sound framework the paramater is called "filename" and should be called as message of the alert

thanks in advance

greez

1

2 Answers 2

3
 - (void)playSound:(NSString *)filename { // method body } // calling [self playSound:@"MusicFile"]; 
Sign up to request clarification or add additional context in comments.

Comments

1

Make this line:

void playSound(char filename) 

into this:

void playSound(NSString *filename) 

The @ "foo" construction says "this is an NSString".

Also, if you want to keep it a C function, you might want to move it out of the @implementation block.

You will find that virtually everything asking for a string in Cocoa will want an NSString, and not a char *.

Oh yeah, and the (char filename) won't work in plain C either, that a single byte variable, not a pointer to a potential string.

1 Comment

If you really want it to be a C function, not an Objective-C method, you also need to move it outside the class.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.