What is the maximum length of an NSString object?

I would assume the hard limit for NSString would be NSUIntegerMax characters, since NSString’s index and size-related methods return an NSUInteger. Since all devices currently capable of running iOS are 32 bit, this means NSUIntegerMax is 2^32 – 1 and NSString can hold a little over 4.2 billion characters.

As others have pointed out, though, the practical limit is much smaller – on an iOS device especially, you’ll run out of memory long before you hit any hard limit in NSString.

Leave a Comment