EXC_BAD_INSTRUCTION仅在iPhone 5模拟器中 [英] EXC_BAD_INSTRUCTION only in iPhone 5 simulator

查看:87
本文介绍了EXC_BAD_INSTRUCTION仅在iPhone 5模拟器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone 5模拟器上运行我的代码将引发图中显示的异常. 在其他任何模拟器上运行代码都很好.

Running my code on the iPhone 5 simulator throws the exception shown in the image. Running the code on any of the other simulators is just fine.

在这种引人注目的代码行中,我无法发现自己​​在哪里犯了错误. 还有其他人有这个问题吗?

I can't spot where I made a mistake in this unspectacular line of code. Does anyone else have this problem?

推荐答案

NSInteger(在Swift中是Int的类型别名)是32位 32位平台(如iPhone 5)上的整数.

NSInteger (which is a type alias for Int in Swift) is a 32-bit integer on 32-bit platforms like the iPhone 5. The result of

NSInteger(NSDate().timeIntervalSince1970) * 1000

1480106653342(目前),不适合 范围-2^31 ... 2^31-1的32位(有符号)整数. 因此,Swift中止执行. (Swift不会截断" 在某些情况下完成的整数算术运算的结果 其他编程语言,除非您专门使用 溢出"运算符,如&*.)

is 1480106653342 (at this moment) and does not fit into the range -2^31 ... 2^31-1 of 32-bit (signed) integers. Therefore Swift aborts the execution. (Swift does not "truncate" the result of integer arithmetic operations as it is done in some other programming languages, unless you specifically use the "overflow" operators like &*.)

您可以使用Int64 all 平台上进行64位计算:

You can use Int64 for 64-bit computations on all platforms:

Int64(NSDate().timeIntervalSince1970 * 1000)

在您的情况下,如果需要一个字符串:

In your case, if a string is needed:

let lastLogin = String(Int64(NSDate().timeIntervalSince1970 * 1000))

这篇关于EXC_BAD_INSTRUCTION仅在iPhone 5模拟器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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