Today, when conducting a string test, I've customized a class that inherits from NSString, but there are some problems, and when you look at the official documentation, you get the following conclusions
In objective-*str =*str = [bfstring stringWithFormat:@ "test"];
Operation Result:
after viewing official documents: To provide a storage mechanism for the characters in a string, these storage mechanisms can be static arrays, dynamically allocated caches, NSString objects, or other data types. The first is the need to provide a storage mechanism for a subclass of strings, followed by two methods to implement@interfacebfstring:nsstring{NSString*_backingstore;}@endthen in the implementation method, overwrite the above two methods length and Characteratindex:, of course, also to overwrite the initialization method@implementationbfstring- (ID) Initwithstring: (NSString *) astring{if(self =[self init]) {_backingstore=[[NSString stringwithstring:astring] copy]; } returnSelf ;}-(Nsuinteger) length{return[_backingstore length];}-(Unichar) Characteratindex: (Nsuinteger) index{return[_backingstore Characteratindex:index];}@endstoring a string in _backingstore and then reading the string to get the length and character of the subclass string now, there is no problem inheriting this subclass of NSString. This practice also applies to Nsarray, nsdictionary, nsnumber, etc.
Inherit Nsstring,nsarray how to write