//------------------------------------------------swift
//可變的字典 NSMutableDictionary數組
//第一種定義方式 返回一個空的字典spa
NSMutableDictionary *mutableDict1 = [NSMutableDictionary dictionary];3d
//第二種定義方式 返回一個空的字典 而且建立一個初始的存儲空間指針
NSMutableDictionary *mutableDict2= [[NSMutableDictionary alloc]initWithCapacity:10];orm
//第三種定義方式 返回一個字典 裏面包含裏了一個已建立過的不可變的字典集合對象
//返回數組集合裏面包含字典裏的全部的Key數據ci
NSArray *array1 = [mutableDict2 allKeys];字符串
//利用Key數組的有序性,返回字典裏的Valuestring
for( int i = 0 ; i < [mutableDict2 count]; i++ ){
NSLog(@"key: %@, value: %@",array[i], mutableDict2[array1[i]]);
}
//---------------枚舉-----------------
//swift 語言中的三大語言類型 enum struct class
//定義
//c的枚舉
enum name {
age = 10,
score = 90
};
//typedef 定義類型的別名 再枚舉不容許重複定義
typedef enum
{
scoreI = 80
}name1;
//OC的枚舉 經常使用枚舉:是一個抽象類,它能枚舉的形式把例如數組和字典等集合列舉出來
//例如列舉字典 通常只能列舉出來字典的鍵
NSDictionary *dictIII = @{@"1-1":@"name",@"1-2":@"age",@"1-3":@"score"};
//返回的是一個集合裏的枚舉數據
NSEnumerator *enumerator = [dictIII objectEnumerator];
id dictI ;
//返回集合的下一個對象 列舉
while (dictI = [enumerator nextObject]) {
NSLog(@"%@",dictI);
}
//-----------結構體-------------
//C的結構體
//申明一個結構體,設置結構體裏的屬性
//注意:結構體不能在初始賦值
struct structI{
//NSString *name;
};
//注意:在OC的ARC(自動引用計數)的狀況下,不能設置結構體屬性
//struct structI structII= { .name = @"jack" };
//NSLog(@"structII name: %@", structII.name );
//OC的經常使用結構體:NSRange 、NSRect 、NSPoint 、NSSize
//結構體通常不須要指針表示
//1.NSRange: 通常用於描述一個範圍,一般用於字符串、對象查找
//location: 起始位置 ,length: 長度
NSString *string = @"1234567890";
NSRange rangeII = NSMakeRange( 8, 2 );
//經過字符串返回範圍
NSRange rangeI = [ string rangeOfString:@"90"];
//經過範圍返回字符串
NSLog(@"%@", [string substringWithRange:rangeII]);
NSLog(@"location: %li, length: %li", rangeI.location, rangeI.length );
//2.NSPoint 用於描述一個座標 x,y
NSPoint pointI = NSMakePoint( 3.4, 1.2 );
CGPoint pointII = NSMakePoint( 3.5, 1.3 );
NSLog(@"x:%.2f, y: %.2f", pointI.x, pointI.y );
NSLog(@"x:%.2f, y: %.2f", pointII.x, pointII.y );
//3.NSSize 用於描述一個寬高,width,height
NSSize sizeI = NSMakeSize( 300 , 120 );
CGSize sizeII = NSMakeSize( 300.1 , 120.1 );
NSLog(@"width : %.2f , height: %.2f", sizeI.width, sizeI.height);
NSLog(@"width : %.2f , height: %.2f", sizeII.width, sizeII.height);
//4.NSRect 用戶描述一個座標以及寬高
NSRect rectI = NSMakeRect( 1, 2.1, 100, 200.1);
NSLog(@"x: %.2f , y: %.2f , width: %.2f , height: %.2f",
rectI.origin.x, rectI.origin.y, rectI.size.width, rectI.size.height);
//-----------NSDate------------
//拿到時間
NSDate *date = [[NSDate alloc]init];
////有時區差
//須要格式化
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
//設置要格式成什麼時間格式
//HH是二十四小時制,hh是十二小時制
[dateFormatter setDateFormat:@"yyyy年MM月dd日 HH時mm分ss秒"];
NSLog(@"%@",[dateFormatter stringFromDate:date]);
//把字符串轉換成NSNDate dateFromString
//注意:字符串的格式要和時間格式同樣
//---------- NSvalue----------
//定義一個NSValue
NSValue *value = [[NSValue alloc]init];
//做用:結構體不能直接存放到一個數組中,要先轉換成NSValue類型,而後再放入到數組中
//常見結構體:NSRange NSPoint NSSize NSRect
//將rect轉換成NSValue
NSValue *valueI = [NSValue valueWithRect:rect];
//轉換後存入數組
NSArray *array = @[valueI];
NSLog(@"%@",array);