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]);

        }

  • 相关阅读:
    对scrapy经典框架爬虫原理的理解
    js的处理技巧
    网站登陆的两种方法
    scrapy批量下载图片
    [转]解决scrapy下载图片时相对路径转绝对路径的问题
    scrapy爬取西刺网站ip
    logging的使用方法
    scrapy中的response
    scrapy中的request
    scrapy.Spider的属性和方法
  • 原文地址:https://www.cnblogs.com/csj007523/p/2600889.html
Copyright © 2011-2022 走看看