// Directly assigning the value.
NSString *str = [objDictionary objectForKey:@"attributeName"];
// Assigning with convenience method
NSString *str = [NSString stringWithFormat:@"%@", [objDictionary objectForKey:@"attributeName"]];
// Assigning after being owner to that object.
NSString *str = [[NSString alloc] initWithString:@"%@", [objDictionary objectForKey:@"attributeName"]];
In what cases, We need to identify which one needed to be used in code. ???
Any Reference links for difference between the same???
Or can someone answer the question in depth???
Thanks for the help.
This is the declaration where you want to user local variable with autorelease memory assigned
i.e. you don’t need to worry about memory allocation/deallocation.
This method is useful when you need to combine different types in single string
i.e. integer/float with string
for e.g.
This will result in ‘your value and 5’
This is the assignment where you are allocating memory and you need to have that variable to use some other place so it will be there until and unless you release the memory of that variable.
Make sure when you allocate memory you release memory yourself as you are the responsible one.
For further detailed study I recommend you to visit documentation for NSString which will give you idea about available class/instance methods and how to use.