This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
DataSource and Delegate use of NSInteger
instead of NSUInteger
in regards to Swift and Casting
#296
Labels
Milestone
I've just updated an old project to Swift 3.0 and had to swap to the "feature" branch to get the benefits of #214 to allow my project to build. To expand upon that fix though, I'd love to see a minor enhancement.
When it comes to Swift, uses of
NSUInteger
instead of justNSInteger
for delegate calls such as:and
can cause issues in regards to casting.
These translate to
UInt
(as you'd expect), but because Swift is such a strict language, using them in a simple way, requires casting betweenUInt
andInt
(and vice versa).For example:
The above will show a build error unless you specifically cast
myArray.count
inInt(myArray.count)
.Likewise:
This also fails unless you add an extra line of
let index = Int(index)
to make sure you're passing aInt
to the array subscript.I understand why
NSUInteger
has been used, as an array is unlikely to have an index < 0, but this sadly does cause extra code issues for Swift users (minimal, I agree, but still). Also, this is going away from the standards that delegate calls inUITableViewDataSource
andUICollectionViewDataSource
use, where justNSInteger
is used.I'd love to hear what you think, and allow this to be considered, as it would help a lot with some unnecessary code for Swift users, with minimal impact for Objective-C users.
The text was updated successfully, but these errors were encountered: