0

I am trying to convert UInt64.max to a String.

A line such as:

var str: String = UInt64.max

Results in an error in XCode that:

'UInt64' is not convertible to 'String'

As another example, a line such as the following:

let strFromUInt: String = NSNumber(unsignedLongLong: UInt64.max)

Results in an error in XCode that:

'NSNumber' is not convertible to 'String'

Sorry if I'm missing anything here, I'm quite new to iOS development still. Thanks!

Ezra Free
  • 748
  • 7
  • 19

2 Answers2

7

What's wrong with:

var str = String(UInt64.max)

Basically that's the first thing you should try; in Swift, coercion works by initializing the desired type based on a value of another type.

matt
  • 485,702
  • 82
  • 818
  • 1,064
1

You can do it like this,

var str = "\(UInt64.max)"
Sandeep
  • 20,199
  • 7
  • 63
  • 104