OC-NSDictionary

//

//  main.m

//  nsdictionry_new

//

//  Created by qianfeng on 14-11-9.

//  Copyright (c) 2014年 qianfeng. All rights reserved.

//


#import <Foundation/Foundation.h>

#define PATH @"/Users/qianfeng/Desktop/date.txt"

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        /*

        // insert code here...

        //以键值对的形式

        //键可以使任何对象,键一般使用字符串

        NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"one",@"1",@"tow",@"2",@"thiree",@"3", @"d",@"g",nil];

        //字典存储对象的地址没有顺序,不考虑顺序

        //元素下标为偶数的为值,奇数为键

        NSLog(@"%@",dictionary);

        //字典遍历分为值遍历和键遍历

        

        //遍历器遍历

        NSEnumerator *rator = [dictionary keyEnumerator];

        id obj;

        while (obj  = [rator nextObject]) {

            NSLog(@"%@",obj);

        }

        

        //快速遍历

        for (id obj in dictionary) {

            //键

            NSLog(@"%@",obj);

            //值

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

        }

        

        //通过键,来寻找值:

        NSString * str = [dictionary objectForKey:@"1"];

        NSLog(@"str :%@",str);


        

        //可变字典:

        NSMutableDictionary *mudict = [[NSMutableDictionary alloc] init];

        [mudict setObject:@"one" forKey:@"1"];

        [mudict setObject:@"tow" forKey:@"2"];

        [mudict setObject:@"three" forKey:@"3"];

        [mudict setObject:@"four" forKey:@"4"];

        NSLog(@"%@",mudict);

        [mudict removeObjectForKey:@"1"];

        NSLog(@"%@",mudict);

        NSLog(@"Hello, World!");

        */

//        NSDictionary *newdictionary = @{@"1": @"one"};

        

       /*

        NSString *fileread = [NSString stringWithContentsOfFile:PATH encoding:NSUTF8StringEncoding error:nil];

        

        

        if (fileread) {

            NSLog(@"%@",fileread);

        }

        

        NSDictionary *newDictionary = [NSDictionary dictionaryWithContentsOfFile:fileread];

        

    

        

        NSLog(@"%p",newDictionary);

        NSLog(@"dic:%@",newDictionary);

        NSString *nsstr = [newDictionary objectForKey:@"abidance"];

        NSLog(@"nsstr:%@",nsstr);

        

        NSString *str = @"s :t :r :i n g b u g";

        NSArray *arr  = [str componentsSeparatedByString:@" "];

        NSLog(@"%@",arr);

        

        NSArray *arry = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@":"]];

        NSLog(@"%@",arry);

        NSMutableArray *muarray = [NSMutableArray arrayWithArray:arry];

        

       [muarray removeObject:@" "];

        NSLog(@"%@",muarray);

        */

        NSString *str1 = @"I am a handsome boy hello word";

        NSString *str2 = @"I am a beautiful girl";

        NSArray *array_1 = [str1 componentsSeparatedByString:@" "];

        NSMutableArray *muarray = [[NSMutableArray alloc] init];

        NSArray *array_2 = [str2 componentsSeparatedByString:@" "];

//        NSEnumerator *enumerator = [array_1 reverseObjectEnumerator];

        /*

        int inay_1 = (int)[array_1 count];

        int inay_2 = (int)[array_2 count];

        int temp = ((inay_1 > inay_2)?inay_1:inay_2);

        for (int i = 0; i<temp; i++) {

            if (i<inay_1) {

                [muarray addObject:[array_1 objectAtIndex:i]];

            }

            if (i<inay_2) {

                [muarray addObject:[array_2 objectAtIndex:i]];

            }

        }

        NSLog(@"%@",muarray);

        

        

        NSString *lin = [muarray componentsJoinedByString:@" "];

        NSLog(@"%@",lin);

        */

        NSArray *button_name = @[@"up",@"down",@"left",@"right"];

        NSArray *key_name = @[@"1",@"2",@"3",@"4"];

        NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:button_name forKeys:key_name];

        

        

        

        

        

    }

    return 0;

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值