gpt4 book ai didi

ios - 输入输出字符串函数

转载 作者:行者123 更新时间:2023-11-28 22:25:46 25 4
gpt4 key购买 nike

抱歉听起来像菜鸟,但我如何在 Objective C 中为 iPhone 应用程序创建输入/输出函数。

我想做的是创建一个函数,我将一个字符串传递给它,该字符串在函数中进行评估,然后它以字符串形式返回结果。

这就是我到目前为止所做的,这当然是错误的,因为它无法编译。

在我的 *.h 文件中

void my_func(NSString *string);

在我的 *.m 文件中

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


}

最佳答案

将返回类型从 void 更改为 NSString *。顺便说一句——这是一个函数,而不是一个方法。有什么理由吗?

NSString *my_func(NSString *string)

关于ios - 输入输出字符串函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19079969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com