What is the maximum length of an NSString object?

前端 未结 3 605
有刺的猬
有刺的猬 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:54

    NSString is actually a class-cluster, so it is highly possible that different concrete classes (say, NSString vs. NSMutableString) will make us of different "backing stores" for storing the data. You could even subclass NSString and provide your own backing store implementation, for specific needs you might have (look at "Subclassing Notes" for NSString).

    As to which backing store is actually used by NSString, this is an implementation detail that is not documented by Apple, and it could change at any time.

    For myself, I assume that the maximum length of an NSString is only limited by available memory. Actually, since available memory can be really huge, there will be some other limit (maybe a performance related one), but I have never incurred in such limit.

提交回复
热议问题