如何将int转换为NSString? [英] How can I convert an int to an NSString?

查看:93
本文介绍了如何将int转换为NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Objective-C中将int转换为字符串.我该怎么办?

I'd like to convert an int to a string in Objective-C. How can I do this?

推荐答案

原语可以转换为具有@()表达式的对象.因此,最短的方法是将int转换为

Primitives can be converted to objects with @() expression. So the shortest way is to transform int to NSNumber and pick up string representation with stringValue method:

NSString *strValue = [@(myInt) stringValue];

NSString *strValue = @(myInt).stringValue;

这篇关于如何将int转换为NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆