Note:
What if the NSMutableArray is nil ?
NSMutableArray *mutableArray = nil;
NSArray *array = [NSArray arrayWithArray:mutableArray];
In the above case,the array is returned as an empty array.
(array == @[] )
For Example:-
(Which is an empty array but not nil).
2)NSArray *array = [mutableArray copy];
Note:
What if the NSMutableArray is nil ?
NSMutableArray *mutableArray = nil;
NSArray *array = [mutableArray copy];
The above code returns array as nil. (array==nil)
3)
NSArray *array = [[NSArray alloc] initWithArray:mutableArray];
It returns an array which is not autoreleased.
Note:
NSArray *array = [NSArray arrayWithArray:mutableArray];
It returns an array which is autoreleased.
Read:-
Top iOS Interview Questions And Answers for Beginners
Most Important iPhone interview Questions and Answers
2.How to convert an NSArray to String in Objective-C ?
Answer:-
NSArray *array1 = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSString *StringVal = [array1 componentsJoinedByString:@","];
It returns a String with value "abc".
Read:
Basic iOS interview Questions And Answers
Most Important iPhone interview Questions and Answers
3.How to convert an NSMutableArray to String in Objective-C ?
Answer:-
MArray = [[NSMutableArray alloc] init];
[MArray addObject:@"ABCD"];
[MArray addObject:@"EFGH"];
NSString *StringVal=[MArray description];
OR
NSString *StringVal=[MArray componentsJoinedByString:@", "];
Read:
What are the differences between Cocoa and Cocoa Touch?
In-App Purchase Tutorial in Cocos2d-x using SDKBOX .
4.How to sort an NSMutableArray with custom objects in it?
Answer:-
We can easily sort an array using Blocks.
NSArray *MySortedarray;
MySortedarray = [BillDetails sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { NSDate *first = [(Person*)a birthDate];
NSDate *second = [(Person*)b birthDate];
return [first compare:second];
}];
Read:
Best Tutorials- Properties in objective C
Top 5 Simple iOS Interview Questions And Answers
5.How can I fill an NSMutableArray dynamically?
Answer:-
int count = [CArray count];
NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:count];
for (NSString *name in CArray) {
UIImage *image = [UIImage imageNamed:name];
[resultArray addObject: image];
}
Read:
What is the difference between IBOutlet and IBAction in iOS ?
Top iOS interview Questions And Answers Collection
6.How to replace content of NSMutableArray with NSArray ?
Answer:
DataArray = [resultArray mutableCopy];
In the above example, DataArray is NSMutableArray and resultArray is NSArray.
OR
NSMutableArray *DataArray = [[NSMutableArray alloc] initWithContentsOfArray:resultArray];
Read:
Some important points About View Controller.
What Are The Main Responsibilities Of A View Controller ?
Explain The Difference Between loadView() And viewDidLoad() in iOS
How To Explain UIViewController Life Cycle in iOS ?