Swift では基本的に UInt より Int を用いるようにする

Swift では非負整数であることが自明な場合でも, 特別な理由がない場合 UInt より Int を用いるのが良いようです.

Int/UInt はそれぞれ Objective-C の NSInteger/NSUInteger に相当し, 32bit プラットフォームでは 32bit, 64bit プラットッフォームでは 64bit の符号付き/符号なし整数です.

The Swift Programming Language の Language Guide に以下のような記述があります.

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.

これによるとプラットフォームのワードサイズと同じ大きさの符号なし整数型が必要な時のみ UInt を使うべきで, たとえ格納される値が非負であることが自明な場合でも Int を使うようにしたほうが好ましいとのことです.

Int を使うべき理由としては, コードの相互運用性を助け, 異なる数値型の間を変換する必要を避けることなどが挙げられています.

Swift では Objective-C とは異なり, Int <-> UInt の間での型変換は明示的に記述する必要があるため, Apple のドキュメントにあるように通常は Int を用いるようにしたほうが不要な型変換を書かずに済むため良さそうです.