Swift expression was too complex to be solved in reasonable time

前端 未结 1 1385
无人及你
无人及你 2020-12-11 17:00

I\'m having an error when compiling a project in Xcode, it says:

Expression was too complex to be solved in reasonable time; consider breaking up the

相关标签:
1条回答
  • 2020-12-11 17:52

    Why not reduce the complexity for the compiler by breaking the expression down into two sub-expressions?

    static func random(min: CGFloat, max: CGFloat) -> CGFloat {
        let rand = CGFloat(arc4random()/0xFFFFFFFF)
        return (rand * (max - min) + min)
    }
    

    You can also use UINT32_MAX (or the more "Swifty" UInt32.max or .max) in place of 0xFFFFFFFF to improve readability. If I recall, 0xFFFFFFFF is the hex value of the max value of an unsigned 32-bit Integer as defined in the <stdint.h> header.

    #define UINT32_MAX 0xffffffff  /* 4294967295U */
    
    0 讨论(0)
提交回复
热议问题