Use NSInteger instead of int for 32/64 bit safety

Use `NSInteger` instead of the primitive int for better 32/64 bit compatibility. Also eliminates implicit conversions between `int`, `NSInteger`, and `NSUInteger`.