NSMutableString objects provide methods to modify the underlying array of characters they represent, while NSString does not.
NSMutableString exposes methods such as appendString, deleteCharactersInRange, insertString, replaceOccurencesWithString, etc.
All these methods operate on the string as it exists in memory.
It is a create-once-then-read-only string.
you'll find that all of its "manipulation" methods (substring, uppercaseString, etc) return other NSString objects and never actually modify the existing string in memory.
NSString *simpleString = [[NSString alloc] initWithString:@"simple String"];
simpleString = [simpleString stringByAppendingString:@"OK"];
NSMutableString *mutableString = [[NSMutableString alloc] initWithString:@"MutableString"];
Both of these, functionally, do the same thing except but - the top code block leaks.
generates a new immutable NSString object which you then tell the pointer to point to.
In the process, however, you orphan the NSString object that it originally pointed to.
some key concepts for an iPhone developer to learn as a fresher
3.Difference b/w Data Source and Delegate?
A delegate type object responds to actions that another object takes.
For example, the UITableViewDelegate protocol has methods such as didSelectRowAtIndexPath for performing actions upon a user selecting a particular row in a table.
Whereas a data source type object gives data to another object.
For example again, the UITableViewDataSource protocol has methods such as cellForRowAtIndexPath and numberOfRowsInSection dictating what should be displayed in the table.
What are required delegates and data sources for Table View?
Confusion about delegate and protocol in Objective-C
4.What's the difference between a dictionary and an array?
An NSArray is an 'ordered collection' - every item in the collection has an integer index, so there is an explicit order to the items.
If you swap the order of items in the collection then the collection is no longer the 'same' as the order is different.
An object may appear more than once in the collection.
An NSDictionary is an 'indexed collection' - every item in the collection has a key and can be retrieved with that key.
An object may appear more than once, in that different keys may point to the same object, but a key can only appear once.
A dictionary is also a form of 'hash table' if you have a computer science background
Both arrays and dictionaries are containers and can be read sequentially (e.g. arrays can be enumerated by means of an index and dictionaries by means of a key). But while arrays maintain the order among objects, dictionaries doesn't.
Top 5 Simple iOS Interview Questions And Answers
Most Important iPhone interview Questions and Answers
5.What is the difference between NSSet, NSArray and NSDictionary?
An NSArray can hold objects in a sorted order.
So object1 is always object1, and object2 is always object2.
You can retrieve the first and last object from the array.
An NSSet is much like an NSArray, the only difference is that the objects it holds are not ordered.
So when you retrieve them they may come back in any random order, based on how easy it is for the system to retrieve them.
You would typically use a set when access speed is of the essence and order doesn’t matter, or is determined by other means (through a predicate or sort descriptor).
Core Data for example uses sets when managed objects are accessed via a to-many relationship.
The NSDictionary class is a bit of a magical one: it stores objects as key value pairs. Objects are not ordered, but can be retrieved simply by addressing them with an arbitrary string value.
Top iOS Interview Questions And Answers for Beginners
Core Data Interview Questions and Answers