Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should we use NSString and NSMutableString?

I want to when should we use NSString and when should we use the NSMutableString, because we can append the string in NSString also,so what is the effective use of NSMutableString in Objective C programming?

like image 342
User97693321 Avatar asked Sep 01 '11 18:09

User97693321


People also ask

What is the difference between string and NSString?

Essentially, there is no difference between string and String (capital S) in C#. String (capital S) is a class in the . NET framework in the System namespace. The fully qualified name is System.

What does NSString mean?

A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.

Do I need to release NSString?

If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.

What is NSMutableString?

NSMutableString is the abstract base class for a cluster of classes representing strings whose contents can be changed. It inherits from NSString. It extends the interface it inherits from NSString by adding methods to change the string contents.


1 Answers

I expect MutableString will be slightly more efficient in terms of memory as you are indicating early on that the program may need memory dynamically. NSString is likely to be allocated a single, suitably sized block of memory.

With NSString and its stringBy... methods, you are creating new objects, releasing the old one (if need be) and making the new object autorelease. (Take care if you are changing from non-autorelease to autorelease, you may have a release in your dealloc that isn't needed anymore)

like image 66
James Webster Avatar answered Sep 19 '22 17:09

James Webster