我刚开始使用Objective-C并且有一个(可能)非常非常基本的问题/问题.
int testf(int x){
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
NSString *infstr=[dateFormatter stringFromDate:[[NSDate] dateByAddingTimeInterval:(60*x)];
return infstr;
}
NSString *testString=testf(1);
Run Code Online (Sandbox Code Playgroud)
我目前有以下问题:我不知道如何从函数返回一个字符串.我甚至无法通过谷歌解决这个问题.
上述代码会导致警告"没有强制转换的整数指针".我希望有人确实知道这个"问题"的解决方案,并愿意与我分享.
提前致谢.
您需要使用int创建NSString对象.
NSString *testf(int x) {
return [NSString stringWithFormat:@"%i",x];
}
NSString *testString = testf(1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |