NSString stringWithFormat很慢 [英] NSString stringWithFormat is slow

查看:74
本文介绍了NSString stringWithFormat很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中,方法stringWithFormat:似乎非常慢,实际上是我们的一个应用程序中的一个大瓶颈(我们使用探查器来找出问题). 有没有办法对其进行优化或使用一些更快的C代码?

In Objective-C, the method stringWithFormat: seems to be extremely slow and is actually a large bottleneck in one of our apps (we used the profiler to find that out). Is there a way to optimise it or use some faster C code?

推荐答案

是 在c http://www.cplusplus.com/reference/cstdio/sprintf/中使用sprintf 之后,用[NSString stringWithUTF8:];

Yes use sprintf in c http://www.cplusplus.com/reference/cstdio/sprintf/ after that push the char* in a NSString with [NSString stringWithUTF8:];

示例:

char cString[255];
sprintf (cString, "%d", 36);
NSString* OCstring = [[NSString alloc] initWithUTF8String:cString];

这篇关于NSString stringWithFormat很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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