3

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
  • 808
  • 11
  • 21

2 Answers2

9

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
  • 515,959
  • 87
  • 875
  • 1,141
1

You can do it like this,

var str = "\(UInt64.max)"
Sandeep
  • 20,908
  • 7
  • 66
  • 106