Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't Array.count a UInt? [duplicate]

Why isn't Array.count a UInt instead of an Int?

How could Array.count ever be negative?

like image 912
ma11hew28 Avatar asked Jun 23 '16 18:06

ma11hew28


1 Answers

From Apple's documentation on Swift types here:

NOTE

Use UInt only when you specifically need an unsigned integer type with the same size as the platform’s native word size. If this is not the case, Int is preferred, even when the values to be stored are known to be non-negative. A consistent use of Int for integer values aids code interoperability, avoids the need to convert between different number types, and matches integer type inference, as described in Type Safety and Type Inference.

like image 77
Hayden McCabe Avatar answered Nov 03 '22 04:11

Hayden McCabe