[SOLVED] Difference between NSRange and NSMakeRange


Is there any difference between:

NSRange(location: 0, length: 5)


NSMakeRange(0, 5)

Because Swiftlint throws a warning when I use NSMakeRange, but I don’t know why.

Thanks for the Help 🙂


The only difference between them is that

NSRange(location: 0, length: 5)

is an initializer for NSRange while

NSMakeRange(0, 5)

is a function which creates a new NSRange instance (by using the same initializer inside most likely) and actually is redundant in Swift. Swift has simply inherited it from Objective-C. I would stick to the former

Answered By – Andrey Chernukha

Answer Checked By – Mildred Charles (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *