ARC 中不允许从 NSInteger 到 NSString 的隐式转换。应该使用什么解决方法来处理整数

发布于 2024-12-21 01:30:12 字数 373 浏览 3 评论 0原文

这是我在 viewcontroller.m 文件中的代码,

- (void)viewDidLoad{
[super viewDidLoad];
[self.abilitygeneration setText:((TestAbility *)[self.testabilities objectAtIndex:0]).abilitygeneration]; }

它给了我一个错误:ARC 不允许将 NSInteger 又名 int 隐式转换为 NSString。如何启用 ARC 并找到解决方法。除了 setText,我可以使用什么?

ability Generation 在 TestAbility.h 文件中设置为 NSInteger ..谢谢

This is my code in my viewcontroller.m file

- (void)viewDidLoad{
[super viewDidLoad];
[self.abilitygeneration setText:((TestAbility *)[self.testabilities objectAtIndex:0]).abilitygeneration]; }

It gives me an error implicit conversion of NSInteger aka int to NSString is disallowed with ARC. How do I enable ARC and have a workaround for this.Instead of setText what can I use?

abilitygeneration is set as NSInteger in TestAbility.h file.. thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-12-28 01:30:12

因此,如果我理解正确的话, setText: 接受一个 NSString 而你有一个 NSInteger ?如果这是正确的,您可以按如下方式显式转换它们:

[self.abilitygeneration setText:[NSString stringWithFormat:@"%d",((TestAbility *)[self.testabilities objectAtIndex:0]).abilitygeneration]];

So if I've understood correctly, setText: takes an NSString and you have an NSInteger? If that's correct you can explicitly convert them as follows:

[self.abilitygeneration setText:[NSString stringWithFormat:@"%d",((TestAbility *)[self.testabilities objectAtIndex:0]).abilitygeneration]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文