NSArray is OBJECTIVE-C’s general-purpose array type. It represents an ordered collection of objects, and it provides a high-level interface for sorting and otherwise manipulating lists of data. (Refer to Exploring The Foundation Framework, to know about types of Foundation Classes).
NSArray and its subclass NSMutableArray manage ordered collections of objects called arrays. NSArray creates static arrays, and NSMutableArray creates dynamic arrays. You can use arrays when you need an ordered collection of objects.
Inclined to build a profession as IOS Developer? Then here is the blog post on iPhone Development Certification Training.
NSArray is “toll-free bridged” with its Core Foundation counterpart, CFARRAYREF.
NSArray *brray =[[NSArray alloc]init];
NSArray*aArray =[[NSArray alloc]
initWithObjects:@ “one”,@ “two”,@ “three”, nil];
NSLog (@ “the array is %@”, aArray);
NSArray *aArray =[NSArray arraywithObjects :@ “one, @two”, nil];
NSLog(@ “the array is %@”, aArray);
Int Count = [a Array Count];
NSLog (@ “array is %@”, aArray);
NSString *Second Element = [aArray ObjectAtIndex:1];
Ns log (@ “Second Element is %@, Second Element);
[[NSMutableArray *a mutArray =
[[NSMutableArray alloc] init with objects:@ “hai”,@ “hello”, nil];
[a mutArray addObjects : a Array ];
NSLog(@ “a mutArray is %@”, a mutArray);
// output of an a mutArray is
/ *( Hi, Hello, ( One, Two ) ) */
NSArray *temporary = [a mutArray objectAtIndex:2];
NSString *reqElement = [ tempArray objectAtIndex :1];
NSLog (@ “req.element is %@” , req Element);
[a mutArray removeObjects AtIndex :1 ];
NSLog (@ “ the array after removal is %@”, a mutArray);
Remove all objects:
[a mutArray removeAllObjects];
NSLog (@ “the array remove all objects];
NSLog (@ “ the array after removal is %@”, a mutArray);
[a mutArray insertObject :@ “good” atIndex:1];
NSLog (@ “the insertion of object is %@’, a mutArray);
[a mutArray LastObject];
[a mutArray remove last object];
aArray = one, two, three, four, five…… NSString *Str = @ “five; For (int i=0, i<[aArray Count];i++) { If([aArray objectAtIndex :i]= = str) { // array have five. } } (or) BooL value = [aArray ContainsObjects :Str]; If (value) { }
Frequently Asked iPhone Interview Questions & Answers
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
Name | Dates | |
---|---|---|
IOS Development Training | Jun 10 to Jun 25 | |
IOS Development Training | Jun 13 to Jun 28 | |
IOS Development Training | Jun 17 to Jul 02 | |
IOS Development Training | Jun 20 to Jul 05 |
Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.
1 /15
Copyright © 2013 - 2023 MindMajix Technologies