objective-c之存储集合

//
//  main.m
//  存储集合
//
//  Created by wu jianhua on 16-8-3.
//  Copyright (c) 2016年 wujianhua. All rights reserved.
//

#import <Foundation/Foundation.h>

void testNSSet()
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSSet *set = [[NSSet alloc]
                  initWithObjects:@"string1", @"string2",@"string3",nil];
    
    NSArray *setArray = [set allObjects];
    NSLog(@"The objects in set are %@",setArray);
    
    NSMutableSet *mutableSet = [[NSMutableSet alloc]init];
    [mutableSet addObject:@"string1"];
    setArray = [mutableSet allObjects];
    NSLog(@"The objects in mutableSet are %@",setArray);
    
    [pool drain];
}

void testNSDictionary()
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
                                @"string1",@"key1", @"string2",@"key2",@"string3",@"key3",nil];
    NSString *string1 = [dictionary objectForKey:@"key1"];
    NSLog(@"The object for key, key1 in dictionary is %@",string1);
    
    NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc]init];
    [mutableDictionary setValue:@"string" forKey:@"key1"];
    string1 = [mutableDictionary objectForKey:@"key1"];
    NSLog(@"The object for key, key1 in mutableDictionary is %@",string1);
    
    [pool drain];
    
}

void testNSArray()
{
    
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSArray *array = [[NSArray alloc]initWithObjects:@"string1", @"string2",@"string3",nil];
    NSString *string1 = [array objectAtIndex:0];
    NSLog(@"The object in array at Index 0 is %@",string1);
    
    NSMutableArray *mutableArray = [[NSMutableArray alloc]init];
    [mutableArray addObject: @"string"];
    string1 = [mutableArray objectAtIndex:0];
    NSLog(@"The object in mutableArray at Index 0 is %@",string1);
    
    [pool drain];
}


//http://www.yiibai.com/objective_c/objective_c_data_storage.html
int main(int argc, const char * argv[])
{
    testNSArray();
    
    testNSDictionary();
    
    testNSSet();
  
    return 0;
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值