// nsdictionary
nsdictionary *dictionary = [[
nsdictionaryalloc]initwithobjectsandkeys:@"value1",
@"key1", @"value2",
@"key2", @"v3", @"k3",
@"vc9",
@"ko0",@"m",@"ang",@"9",@"aa",
@"aa", @"2", @"sg",
@"-2", nil];
nslog(@"%@", dictionary);
//使用類方法建立
nsdictionary *d =
[nsdictionarydictionarywithobjectsandkeys:@"abc",
@"kkk1", @"abc",
@"k333",
nil];
nslog(@"%@", d);
//隻能賦一個值的方法
nsdictionary *d1 =
[nsdictionarydictionarywithobject:@"vv3"forkey:@"kkkkkkk5"];
nslog(@"%@", d1);
//建立儲存索引key的數組
nsarray *keyarray =
[nsarray
arraywithobjects:@"k1",@"k3",@"k5",
//建立儲存所有value的數組
nsarray *valuearray =
arraywithobjects:@"v1",
@"v3",@"v5", nil];
nsdictionary *d2 =
[nsdictionarydictionarywithobjects:valuearray
forkeys:keyarray];
nslog(@"%@", d2);
//使用一個檔案建立字典對象
nsdictionary *d5 =
[nsdictionarydictionarywithcontentsoffile:@"/users/lanou3g/desktop/deme_4.25/deme_4.25/dict.list.plist"];
nslog(@"%ld",[d5 count]);
//根據key取出一個值
nsstring *p1 = [d5
objectforkey:@"abcd"];
nslog(@"%@", p1);
//取出字典中所有的key
nsarray *allkeys = [d5
allkeys];
nslog(@"%@", allkeys);
//取出所有value
nsarray *allvalue = [d5
allvalues];
nslog(@"%@", allvalue);
//使用枚舉器
nsenumerator *enumerator
=[d5 keyenumerator];
nsstring *str =
nil;
while (str = [enumerator
nextobject]) {
nslog(@"%@", str);
}
//數組中使用枚舉器
nsarray *arr =
[nsarrayarraywithobjects:@"hjds",@"jhnj",@"ihi",
nsenumerator *e =
[arr objectenumerator];
nsstring *str5 =
while (str5 = [e
nslog(@"%@",str5);
nsmutabledictionary *dic1 =
[nsmutabledictionarydictionarywithobject:@"value1"forkey:@"k1"];
nsmutabledictionary *dic2
=[nsmutabledictionarydictionarywithobject:@"value2"forkey:@"k2"];
[dic1
addentriesfromdictionary:dic2];
nslog(@"%@",dic1);
removeallobjects];
setvalue:@"lalala"
forkey:@"123"];
//nsset
//1.使用類方法建立
nsset *set1 =
[nsset set];
//建立一個空的集合對象
nsset *set2 =
[nssetsetwithobject:@"abc"];
nsset *set3 =
[nsset
setwithobjects:@"hahaha",@"hehehe",@"eee",
nslog(@"%@", set2);
nslog(@"%@", set3);
[nsarrayarraywithobjects:@"abc",@"bcd",@"cdf",
nsset *set4 =
[nsset setwitharray:arr];
nslog(@"----------%@", set4);
nsset *set5 =
[nssetsetwithobject:@"wow"];
nslog(@"%@", set5);
nsset *set6 =
[nsset setwithset:set3];
nsset *set7 =
[nsset setwithobjects:set6,set2,
nslog(@"+++++%@", set7);
//使用執行個體方法建立集合
nsset *s1 =
[[nssetalloc]initwithobjects:@"abc",@"bcd",
nsset *s2 =
[[nssetalloc]initwithset:s1];
nslog(@"%@", s2);
nsset *s3 =
[[nssetalloc]initwitharray:[nsarrayarraywithobjects:@"abc",@"bcd",@"cdf",
nil]];
nslog(@"%@", s3);
nsset *s4 =
[[nssetalloc]initwithset:s1
copyitems:no];
nslog(@"%@", s4);
nslog(@"%ld",[s3 count]);
[s3 objectenumerator];
nsstring *str
=nil;
while (str = [e
nslog(@"使用枚舉器:%@",str);
nsenumerator *e1 =
while (str5 = [e1
nslog(@"%@", str5);
//判斷是否有交集
nslog(@"%d",[set4
intersectsset:s1]);
//判斷是否相等
isequaltoset:s3]);
//判斷是否是子集
issubsetofset:set5]);
nsmutableset *s6 =
[nsmutablesetsetwithobjects:@"hhh",@"jjj",@"kkk",@"nnn",nil];
nsmutableset *s7 =
[nsmutablesetsetwithobjects:@"hhh",@"jjj",
[s6
intersectset:s7]; //intersectsset
多個intersect“s“是判斷是否有交集
nslog(@"%@",s6);
addobject:@"aaa"];
[s6 minusset:s7];
//取2個集合的并集
[s6 unionset:s7];
//給集合指派
[s7 setset: s3];
nslog(@"%@",s7);
}
return 0;
}
nsinteger
intsort(id num1, id num2,
void *context)
{
int v1 =
[num1 intvalue];
int v2 =
[num2 intvalue];
if (v1
< v2)
return nsorderedascending;
else
if (v1 > v2)
returnnsordereddescending;
return nsorderedsame;