Sam B
Sam B

Reputation: 27608

Input Output String function

Sorry to sound like a noob but how do I create an input / output function in Objective C for an iPhone app.

What I am trying to do is create a function where I pass it a string, the string get evaluated in the function then it returns back result in a string.

This is what I have done so far which of course is wrong as it doesn't compile.

in my *.h file

void my_func(NSString *string);

in my *.m file

void my_func(NSString *string)
{
    NSMutableString *statusBack;


    if ([string isEqualToString:@"26"] )
    {
        statusBack = [NSMutableString stringWithFormat: @"Sunny"];
    }
    else
    {
        statusBack = [NSMutableString stringWithFormat: @"Cloudy"];
    }

    return statusBack; //compile error
}


-(IBAction) customIBAction
{
  //call my custom function 
  //not sure how? 
  NSMutableString *str1 = [NSMutableString stringWithFormat: @"24"];
  NSString *returnedStr = my_func(str1); //compile error


}

Upvotes: 0

Views: 68

Answers (1)

rmaddy
rmaddy

Reputation: 318794

Change the return type from void to NSString *. BTW - this is a function, not a method. Any reason why?

NSString *my_func(NSString *string)

Upvotes: 2

Related Questions