gpt4 book ai didi

ios - 这个 objective-c 代码在 swift 中的等价物是什么?

转载 作者:搜寻专家 更新时间:2023-10-31 08:08:38 24 4
gpt4 key购买 nike

此代码的 swift 替代代码是什么?

static inline CGFloat randomInRangeScale(CGFloat scale)
{
CGFloat value = arc4random_uniform(INT16_MAX);
return value * 0.000015 + 0.8 ;
}

我试过这个:

func randomInRangeScale(scale : CGFloat) -> CGFloat
{
let value : CGFloat = arc4random_uniform(UInt16);
return value * 0.000015 + 0.8 ;
}

但它给了我一个错误 "Cannot invoke 'arc4random_uniform' with an argument list of type '((UInt16).Type)"

最佳答案

这应该可以完成工作

func randomInRangeScale(scale : CGFloat) -> CGFloat {
let random = arc4random_uniform(UInt32(UInt16.max))
let randomCGFloat = CGFloat(random)
return randomCGFloat * 0.000015 + 0.8
}

关于ios - 这个 objective-c 代码在 swift 中的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32026000/

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