Aditya Sharma
Aditya Sharma

Reputation: 605

floating point value can not be converted to UInt32 because it is greater than UInt32.max getting in swift

floating point value can not be converted to UInt32 because it is greater than UInt32.max getting this exception while

var timeSec = UInt32(NSDate().timeIntervalSince1970 * 1000)

Upvotes: 1

Views: 1413

Answers (1)

Maxi Mus
Maxi Mus

Reputation: 815

The range for UInt32 is not large enough for your variable. You can test this in a Playground. The constant UINT32_MAX is 4294967295, much smaller than your value. Use UInt64:

var timeSec = UInt64(NSDate().timeIntervalSince1970 * 1000)

Upvotes: 2

Related Questions