zoukankan      html  css  js  c++  java
  • IOS NSArray,NSDictionary

    小结:

    NSArray有序的集合;

    NSDictionary无序的集合,可排序; 增删改查

    ------NSArray-----------

     create :

    1)NSArray *array = [NSArray arrayWithObjects:@"Henry",@"Jones", @"Susan", @"Smith", @"Patty", @"Johnson", nil]; 

    2)NSArray *myArray = [NSArray arrayWithArray:array];

    NSLog(@"%@", myArray); 

    3) NSMutableArray *array = [[NSMutableArray alloc] initWithObjects: @"Foo", @"Bar", @"FooBar", nil]; 

    4) NSMutableArray *array2 = [NSMutableArray arrayWithCapacity: 3];

    //Add an object

    [array2 addObject: @"Foo"];

    //Add another object

    [array2 addObject: @"Bar"];

    //Insert an object at a particular index

    [array2 insertObject: @"FooBar" atIndex: 1]; 

    5) int n = 15;

    NSMutableArray *numberArray = [[NSMutableArray alloc] initWithCapacity:n];

    //srand(time(0));

    srandom(time(NULL));

    for(int i = 0; i < n; i++)

    [numberArray addObject:[NSNumber numberWithInt:arc4random()%n]];

    NSLog( @"%@", numberArray);

    sort:

    NSArray *sortedArray = 

      [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; 

    ---------dictionary--------------

    NSArray  *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3", nil];

        NSArray *objects = [NSArray arrayWithObjects:@"How", @"are", @"you", nil];

        NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

    //Case 1, loop through 

    for (id key in dictionary) {

            NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);

        }

    //Case 2, loop through 

    NSEnumerator *enumerator;

        id key;

    enumerator = [dictionary keyEnumerator];    

        while ((key = [enumerator nextObject])){  

            NSLog(@"%@====>%@", key, [dictionary objectForKey:key]);

        }

  • 相关阅读:
    python获取公网ip,本地ip及所在国家城市等相关信息收藏
    Tkinter的下拉列表Combobox
    pyinstaller打包pyqt文件(转)
    通过pyqt5实现俄罗斯方块游戏例子
    pygame游戏开发入门例子
    python界面Tkinter编程(tkMessageBox对话框使用)
    python tkinter-菜单栏
    python tkinter-容器、子窗体
    HUNNU--湖师大--11409--Skill
    [置顶] 博客搬迁到新地址。
  • 原文地址:https://www.cnblogs.com/csj007523/p/2600889.html
Copyright © 2011-2022 走看看