//
// 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;
}