When C and Objective-C APIs use NSUInteger as parameter types or return types, they get imported to Swift as Int instead of UInt, but only for Apple’s frameworks like Foundation or AppKit.
This is documented behavior and is fine by me, but it would be nice if there were a way to get the same behavior for my C and Objective-C code.
This would improve consistency in the code base. For example, if a Foundation class uses NSUInteger – like NSData does – it would be nice if my Objective-C categories or subclasses could use the same types as the framework class does: that is, NSUInteger in Objective-C and Int in Swift.
This would probably be an attribute on each single parameter/return type of a method/function declaration.
Maybe something similar to NS_ASSUME_NONNULL_BEGIN/END could be added that can be used to bracket parts of a header to import every NSUInteger occurrence as Int. OTOH, this is by far less common of a problem compared to nullable pointers, so maybe it’s not worth it.
I asked about this on the Swift Users mailing list and Chris Lattner responded by writing that it would be reasonable to introduce a clang attribute for that. Here’s the link to the start of the thread: