2

Here is my code.

var frameCount = INT_MAX
...

let totalSize: UInt32 = 4096
let itemSize: UInt32 = 64
frameCount = totalSize / itemSize

I get "Binary operator '/' cannot be applied to two 'UInt32' operands" error message. Is it really impossible or what did I miss?

Capella
  • 881
  • 3
  • 19
  • 32

1 Answers1

3

The error message is a bit misleading. INT_MAX is defined as

public var INT_MAX: Int32 { get }

so with

var frameCount = INT_MAX

frameCount is defined as a variable of type Int32. The result of the division totalSize / itemSize is a UInt32 however, and Swift does not implicitly convert types.

You can fix that by changing the initial definition to

var frameCount = UINT32_MAX

or perhaps simpler, let the compiler infer the type:

let totalSize: UInt32 = 4096
let itemSize: UInt32 = 64
let frameCount = totalSize / itemSize

If you need the result as a signed integer then you have to convert it explicitly, e.g.

let frameCount = Int32(totalSize / itemSize)
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382