. Array creation
    // Be careful : stay OC In the array , Only objects can be stored 
//    NSArray *array = [NSArray arrayWithObject:12]; error
    // Create string
    NSString *str1 = @"zhangsan";
    NSString *str2 = @"lisi";
    NSString *str3 = @"wangwu";
    // Create array , And set up multiple elements
    // Be careful : In order to nil At the end of the
    NSArray *array1 = [[NSArray alloc] initWithObjects:str1,str2,str3, nil];
    // Use the corresponding class method
    NSArray *array2 = [NSArray arrayWithObjects:str1,str2,str3, nil];
    // Initializing an element while creating an array
    NSArray *array3 = [[NSArray alloc] initWithObjects:str1, nil];
    NSArray *array4 = [NSArray arrayWithObject:str1];
    NSLog(@"array3:%@ \n  array4:%@",array3,array4);
    // Create an array and initialize it with an existing array
    NSArray *array5 = [[NSArray alloc] initWithArray:array2];
    NSArray *array6 = [NSArray arrayWithArray:array2];
    NSLog(@"array5:%@ \n  array6:%@",array5,array6);
    . Get the corresponding elements of the array
    //----------- Take the element according to the subscript ---------
    NSString *str = [array5 objectAtIndex:];
    . Get the number of array elements     NSUInteger count = array5.count; //[array5 count];
    . Determine whether an element is in an array     BOOL isContain = [array5 containsObject:@"zhaoliu"];
    if (!isContain) {
        NSLog(@" It doesn't contain zhaoliu");
    . Get a subscript from an element
    // If there is this element , The corresponding subscript is returned , No return NSNotFound
    NSInteger index = [array5 indexOfObject:@"zhaofei"];
    if (index == NSNotFound) {
        NSLog(@" Elements that don't respond ");
    . Notice the difference between the two arrays     // take array5 All the elements in are given to array8
    NSArray *array8 = [NSArray arrayWithArray:array5];
    NSArray *array9 = [NSArray arrayWithObject:array5];
    NSLog(@"array9:%@",array9);     . Get the top of the array / The last element     NSString *firstStr = [array8 firstObject];
    NSString *lastStr = [array8 lastObject];
    NSLog(@"firstStr:%@  lastStr:%@",firstStr,lastStr);
    . Intercept array
    NSArray *array10 = [[NSArray alloc] initWithObjects:@"",@"",@"",@"",@"", nil];
    // Intercept out @"2",@"3",@"4"
    NSRange rg = {,};
    NSArray *subArray = [array10 subarrayWithRange:rg];
    . Append array
    // Add an element
//    [array10 arrayByAddingObject:<#(nonnull id)#>]
    // stay array10 Append element after
    NSArray *addArray = [array10 arrayByAddingObjectsFromArray:array1];
    NSLog(@"%@",addArray);     . Array comparison
    if ([array1 isEqualToArray:array2]) {
        NSLog(@"array1 and array2 identical ");
    . Determine whether the beginning of two arrays is the same     // 1,2,4,5    3,2,1,6
    NSArray *a = @[@"",@"",@"",@""];
    NSArray *a2 = @[@"",@"",@"",@""];
    NSString *sameS = [a firstObjectCommonWithArray:a2];
    if (![array1 firstObjectCommonWithArray:array10]) {
        NSLog(@" The first element is not the same ");
    . Array traversal     // Mode one :
    // Traverse addArray
    // obtain addArray Length of array
    NSUInteger count2 = addArray.count;
    for (int i=; i<count2; i++) { // Notice that the array is out of bounds
        // Get elements according to subscripts
//        NSString *obj = [addArray objectAtIndex:i];
        // Equivalent
        NSString *obj = addArray[i];
    // Mode two : Fast traverse
    for (NSString *str in addArray) {
    //------------ New syntax for arrays ------------
//    int a[] = {1,2,3,4}
//    a[2]
    // Create and initialize arrays
    NSArray *array11 = @[@"",@"",@"",@"",@""];
    // Get the element according to the subscript
    NSString *s = array11[];
Two : Variable array (NSMutableArray)
    NSString *s1 = @"zhaoliu";
    NSString *s2 = @"tianqi";
    NSString *s3 = @"suba";
    . Create variable arrays
    // You can't write like this
//    NSMutableArray *mutArray = @[s1,s2,s3];
    // Create a capacity of 5 Array of , It can store more than 5 Elements , Space will automatically increase
    NSMutableArray *mutArray1 = [NSMutableArray arrayWithCapacity:];
    // Be careful : There are no elements at this point ,0
    NSUInteger mutCount = mutArray1.count;
    NSMutableArray *mutArray2 = [[NSMutableArray alloc] initWithObjects:s1,s2,s3, nil];
    . Additive elements
//    [mutArray2 addObject:str1];
//    [mutArray2 addObject:str2];
//    [mutArray2 addObject:str3];
    //2. Add elements from an array to a discernible array
    [mutArray2 addObjectsFromArray:array1];
    //3. Add an array as an element to the array
    [mutArray2 addObject:array1];
    . Insert elements     [mutArray2 insertObject:@"" atIndex:];     . Replacement elements
    [mutArray2 replaceObjectAtIndex: withObject:@"bingge"];     
    // You can replace multiple
//    [mutArray2 replaceObjectsInRange:<#(NSRange)#> withObjectsFromArray:<#(nonnull NSArray *)#>]
    . In exchange for
    [mutArray2 exchangeObjectAtIndex: withObjectAtIndex:];
    . Delete
    // Delete all elements
//    [mutArray2 removeAllObjects];
    // Delete the last element
//    [mutArray2 removeLastObject];
    // Deletes the specified element
//    [mutArray2 removeObject:@"bingge"];
//    / Delete the specified subscript element
//    [mutArray2 removeObjectAtIndex:1];
    // Delete multiple elements
    NSRange rg1 = {,};
    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:rg1];
    [mutArray2 removeObjectsAtIndexes:indexSet];
    . Array elements sort     NSArray *array = @[@"agfd",
    NSArray *newArray = [array sortedArrayUsingSelector:@selector(compare:)];

Foundation ----->NSArray More articles about

  1. 【IOS】IOS High speed entry OC grammar

    Objective-C yes C The superset of language You can also access standards C Library routines , For example stdlib.h and stdio.h The routines declared in . Objective-C Or a very dynamic programming language , And this dynamic ...

  2. Object-C Novice tutorial

    The outline Let's get started Download this tutorial Set the environment Preface compile hello world establish Classes @interface @implementation Put them together Specify ... Multiple parameters Constructors ( ...

  3. iOS Expand ——Objective-C Develop programming specifications

    Recently, I'm ready to start learning the development process and ideas of a complete project , Before that , We need to be right about iOS The development of standards into a more systematic and detailed study , At will to the programming specification has carried on the reorganization and the study . This article is mainly reprinted from :Objective-C-Codin ...

  4. [Swift]JSON Strings and dictionaries (Dictionary)、 Array (Array) Mutual conversion between

    1.JSON Strings and dictionaries (Dictionary) Mutual conversion between import Foundation //JSON String to dictionary (Dictionary) func getDictionaryFromJ ...

  5. iOS Naming specification ( Reprint )

    Reprinted address :http://www.cnblogs.com/qiqibo/archive/2012/09/05/2671553.html Text : • formatting code  ◦ The pointer “*” The position of the   Such as :NSStr ...

  6. NSKeyValueObserving.m

    https://github.com/farcaller/cocotron/blob/af740de86c9bee84c59ffc74d27e5df9e22e1391/Foundation/NSKey ...

  7. It is worth learning from Objective-C Programming specification

    Daniel's Objective-C Coding Style Guidelines http://google-styleguide.googlecode.com/svn/trunk/objcg ...

  8. [ translate ] BFKit

    BFKit BFKit is a collection of useful classes to develop Apps faster. BFKit It's a useful collection of tools , Help you develop . Insta ...

  9. kvc and kvo Understanding of the use of

    understand cocoa:Cocoa It's apple for Mac OS X The native object-oriented API, yes Mac OS X Top five API One of them ( The other four are Carbon.POSIX.X11 and Java). Apple's object-oriented open ...

Random recommendation

  1. JSON Style guide - True through

    brief introduction JSON(JavaScript Object Notation) Is a lightweight data exchange format . It's based on ECMAScript A subset of . JSON Use a completely language independent text format , But it also uses something like C language ...

  2. SharePoint About China event receivers The discussion of the

    This morning , I talked about event triggers in the group with some friends , I feel like I've gained a lot , Share it with you . The content of the discussion , It's about synchronization of event triggers / Asynchronous settings and functions . In fact, contact SharePoint for quite a while , For event triggers ...

  3. JLINK V8 upgrade 5.12E stay MDK5.20 The same brick

    Reprint : It's just a new firmware , The steps are the same as the methods provided by atoms It's exactly the same . The steps are also written here . Use SAM-PROG to update JLINK Firmware one : Install the software install Install AT91-ISP v1.13.e ...

  4. Javascript The basic format

    Javascript The basic format ① JavaScript Case sensitive As long as a language is object-oriented , They are all case sensitive , So in Javascript in , The variables are small i And variables I It's two completely different variables ② JavaScrip ...

  5. [Redux] Passing the Store Down Explicitly via Props

    n the previous lessons, we used this tool to up level variable to refer to the Redux chore. The comp ...

  6. C# Webform Read from Windows AD/LDAP List of domain users

    Direct delivery of dry goods , The core code is as follows , Read out the corresponding user list to DataTable in . If you need other fields, you can add them yourself , Don't forget to quote using System.DirectoryServices. #region privat ...

  7. 【LeetCode】98. Validate Binary Search Tree

    subject : Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is define ...

  8. Network programming -Mysql-1、 Database startup and shutdown , Create database , Table and other basic operations

    Start server :sudo service mysql start Turn off the server :suodo service mysql stop Restart the server :suodo service mysql restart Connect data ...

  9. visualbox install

    1. Download address : Official website 2. Installation steps 3. New virtual machine

  10. DSP builder Installation guide ( With 9.1 For example ) from http://www.cnblogs.com/sleepy/archive/2011/06/28/2092362.html

    DSP Builder Help designers generate in an algorithm friendly development environment DSP Design hardware characterization , So it shortens DSP design cycle . Existing MATLAB Functions and Simulink Modules can interact with Altera DSP Builder Modules and ...