What is the maximum length of an NSString object?

前端 未结 3 600
有刺的猬
有刺的猬 2020-11-29 08:22

What is the maximum sized string that can be held in a NSString object?

Does this change dynamically?

3条回答
  •  渐次进展
    2020-11-29 08:31

    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.

提交回复
热议问题