gpt4 book ai didi

ios - 在为iOS应用添加64位支持的同时,首选使用int值的方法

转载 作者:行者123 更新时间:2023-12-01 16:28:59 24 4
gpt4 key购买 nike

我正在更新一个不支持64位体系结构的旧iOS应用。

从Apple的转换过程来看,它好像将“int和unsigned int分别转换为NSInteger和NSUInteger”。但是,这样做时,最终会在格式化期间进行大量的long转换,如下所示。我会担心32位架构的性能,因为所有的转换都花了很长时间。

//old
NSInteger myIntValue = 5;
[NSString stringWithFormat:@"%d", myIntValue];

//new
NSInteger myIntValue = 5;
[NSString stringWithFormat:@"%ld", (long)myIntValue];

一种替代方法是将我对NSInteger的使用替换为int,以便它们保持为4字节值,因此在格式化myIntValue时无需强制转换为long。
//old
NSInteger myIntValue = 5;
[NSString stringWithFormat:@"%d", myIntValue];

//new
int myIntValue = 5;
[NSString stringWithFormat:@"%d", myIntValue];

假设出于某种特殊原因,应该避免使用后一种方法,前提是可以保证将从NSInteger更改为int的项放入4字节的int内?

最佳答案

这些转换是为32- 64位进行编译时格式化字符串的唯一方法,因为替代方法更糟(我认为):

#if __LP64__
[NSString stringWithFormat:@"%ld", myIntValue];
#else
[NSString stringWithFormat:@"%d", myIntValue];
#endif

强制转换没有大的性能问题,因为这仅取决于堆栈上有多少空间以及可能会有一些符号扩展。小东西。

关于ios - 在为iOS应用添加64位支持的同时,首选使用int值的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281906/

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