Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述试图在Swift中调用dispatch_time正在努力,这就是为什么: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), { doSomething() }) 导致错误:“无法找到接受提供的参数的’*’的重载” 试图在Swift中调用dispatch_time正在努力,这就是为什么:
dispatch_after(dispatch_time(disPATCH_TIME_Now,10 * NSEC_PER_SEC),dispatch_get_main_queue(),{            doSomething()            })

导致错误:“无法找到接受提供的参数的’*’的重载”.

NSEC_PER_SEC是一个UInt64,因此可以进行一些实验:

let x:UInt64 = 1000let m:Int64 = 10 * x

导致与上述相同的错误

let x:UInt64 = 1000let m:Int64 = 10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

let x:UInt64 = 1000let m:Int64 = 10 * ((Int64) x)

结果“预期”,“分隔符”

let x:UInt64 = 1000let m:Int64 = (Int64)10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

等等

该死的Swift编译器,我放弃了.如何将UInt64转换为Int64,和/或如何在swift中使用dispatch_time?

将UInt64转换为Int64是不安全的,因为UInt64的数字可能大于Int64.max,这将导致溢出.

这是一个用于将UInt64转换为Int64的片段,反之亦然:

// Extension for 64-bit integer signed <-> unsigned conversionextension Int64 {    var unsigned: UInt64 {        let valuePointer = UnsafeMutablePointer<Int64>.allocate(capacity: 1)        defer {            valuePointer.deallocate(capacity: 1)        }        valuePointer.pointee = self        return valuePointer.withMemoryRebound(to: UInt64.self,capacity: 1) { 
if currentValue < 0 {    return Int64.max + currentValue + 1} else {    return currentValue}
.pointee } }}extension UInt64 { var signed: Int64 { let valuePointer = UnsafeMutablePointer<UInt64>.allocate(capacity: 1) defer { valuePointer.deallocate(capacity: 1) } valuePointer.pointee = self return valuePointer.withMemoryRebound(to: Int64.self,capacity: 1) {
// Using an 8-bit integer for simplicity// currentValue0b1111_1111 // If this is interpreted as Int8,this is -1.// Strip sign bit0b0111_1111 // As Int8,this is 127. To get this we can add Int8.max// Int8.max + currentValue + 1127 + (-1) + 1 = 127
.pointee } }}

这简单地将UInt64的二进制数据解释为Int64,即大于Int64.max的数字将是负的,因为64位整数的最高位的符号位.

如果你只想要正整数,那就得到绝对值.

编辑:根据行为,您可以获得绝对值,或:

[+++]

后一种选择类似于剥离符号位.例如:

[+++] 总结

以上是内存溢出为你收集整理的swift – 如何将UInt64转换为Int64?全部内容,希望文章能够帮你解决swift – 如何将UInt64转换为Int64?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述试图在Swift中调用dispatch_time正在努力,这就是为什么: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), { doSomething() }) 导致错误:“无法找到接受提供的参数的’*’的重载” 试图在Swift中调用dispatch_time正在努力,这就是为什么:
dispatch_after(dispatch_time(disPATCH_TIME_Now,10 * NSEC_PER_SEC),dispatch_get_main_queue(),{            doSomething()            })

导致错误:“无法找到接受提供的参数的’*’的重载”.

NSEC_PER_SEC是一个UInt64,因此可以进行一些实验:

let x:UInt64 = 1000let m:Int64 = 10 * x

导致与上述相同的错误

let x:UInt64 = 1000let m:Int64 = 10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

let x:UInt64 = 1000let m:Int64 = 10 * ((Int64) x)

结果“预期”,“分隔符”

let x:UInt64 = 1000let m:Int64 = (Int64)10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

等等

该死的Swift编译器,我放弃了.如何将UInt64转换为Int64,和/或如何在swift中使用dispatch_time?

将UInt64转换为Int64是不安全的,因为UInt64的数字可能大于Int64.max,这将导致溢出.

这是一个用于将UInt64转换为Int64的片段,反之亦然:

// Extension for 64-bit integer signed <-> unsigned conversionextension Int64 {    var unsigned: UInt64 {        let valuePointer = UnsafeMutablePointer<Int64>.allocate(capacity: 1)        defer {            valuePointer.deallocate(capacity: 1)        }        valuePointer.pointee = self        return valuePointer.withMemoryRebound(to: UInt64.self,capacity: 1) { 
if currentValue < 0 {    return Int64.max + currentValue + 1} else {    return currentValue}
.pointee } }}extension UInt64 { var signed: Int64 { let valuePointer = UnsafeMutablePointer<UInt64>.allocate(capacity: 1) defer { valuePointer.deallocate(capacity: 1) } valuePointer.pointee = self return valuePointer.withMemoryRebound(to: Int64.self,capacity: 1) {
// Using an 8-bit integer for simplicity// currentValue0b1111_1111 // If this is interpreted as Int8,this is -1.// Strip sign bit0b0111_1111 // As Int8,this is 127. To get this we can add Int8.max// Int8.max + currentValue + 1127 + (-1) + 1 = 127
.pointee } }}

这简单地将UInt64的二进制数据解释为Int64,即大于Int64.max的数字将是负的,因为64位整数的最高位的符号位.

如果你只想要正整数,那就得到绝对值.

编辑:根据行为,您可以获得绝对值,或:

后一种选择类似于剥离符号位.例如:

[+++] 总结

以上是内存溢出为你收集整理的swift – 如何将UInt64转换为Int64?全部内容,希望文章能够帮你解决swift – 如何将UInt64转换为Int64?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
swift – 如何将UInt64转换为Int64?_app_内存溢出

swift – 如何将UInt64转换为Int64?

swift – 如何将UInt64转换为Int64?,第1张

概述试图在Swift中调用dispatch_time正在努力,这就是为什么: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), { doSomething() }) 导致错误:“无法找到接受提供的参数的’*’的重载” 试图在Swift中调用dispatch_time正在努力,这就是为什么:
dispatch_after(dispatch_time(disPATCH_TIME_Now,10 * NSEC_PER_SEC),dispatch_get_main_queue(),{            doSomething()            })

导致错误:“无法找到接受提供的参数的’*’的重载”.

NSEC_PER_SEC是一个UInt64,因此可以进行一些实验:

let x:UInt64 = 1000let m:Int64 = 10 * x

导致与上述相同的错误

let x:UInt64 = 1000let m:Int64 = 10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

let x:UInt64 = 1000let m:Int64 = 10 * ((Int64) x)

结果“预期”,“分隔符”

let x:UInt64 = 1000let m:Int64 = (Int64)10 * (Int64) x

结果“一行上的连续陈述必须以’;’分隔”

等等

该死的Swift编译器,我放弃了.如何将UInt64转换为Int64,和/或如何在swift中使用dispatch_time?

将UInt64转换为Int64是不安全的,因为UInt64的数字可能大于Int64.max,这将导致溢出.

这是一个用于将UInt64转换为Int64的片段,反之亦然:

// Extension for 64-bit integer signed <-> unsigned conversionextension Int64 {    var unsigned: UInt64 {        let valuePointer = UnsafeMutablePointer<Int64>.allocate(capacity: 1)        defer {            valuePointer.deallocate(capacity: 1)        }        valuePointer.pointee = self        return valuePointer.withMemoryRebound(to: UInt64.self,capacity: 1) { 
if currentValue < 0 {    return Int64.max + currentValue + 1} else {    return currentValue}
.pointee } }}extension UInt64 { var signed: Int64 { let valuePointer = UnsafeMutablePointer<UInt64>.allocate(capacity: 1) defer { valuePointer.deallocate(capacity: 1) } valuePointer.pointee = self return valuePointer.withMemoryRebound(to: Int64.self,capacity: 1) {
// Using an 8-bit integer for simplicity// currentValue0b1111_1111 // If this is interpreted as Int8,this is -1.// Strip sign bit0b0111_1111 // As Int8,this is 127. To get this we can add Int8.max// Int8.max + currentValue + 1127 + (-1) + 1 = 127
.pointee } }}

这简单地将UInt64的二进制数据解释为Int64,即大于Int64.max的数字将是负的,因为64位整数的最高位的符号位.

如果你只想要正整数,那就得到绝对值.

编辑:根据行为,您可以获得绝对值,或:

后一种选择类似于剥离符号位.例如:

总结

以上是内存溢出为你收集整理的swift – 如何将UInt64转换为Int64?全部内容,希望文章能够帮你解决swift – 如何将UInt64转换为Int64?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1047162.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存