提示: 這篇博文主要介紹了Foundation框架中一些類的使用方法,都是以代碼方式展示的,可能會比較亂,但都是些常用的方法,這些方法常用自然就會記住所以不用糾結,注意主要記方法的第一個單詞,單詞不認識的話可以記前三個字母,再配合提示查找
------------------------------------------------------------------------------------------------------------------
NSURL簡介
什么是URL?
URL的全稱是Uniform Resource Locator(統一資源定位符) URL是互聯網上標準資源的地址 互聯網上的每個資源都有一個唯一的URL,它包含的信息指出資源的位置 根據一個URL就能找到唯一的一個資源
URL的格式?
基本URL包含協議、主機域名(服務器名稱/ip地址)、路徑
可以簡單認為: URL == 協議頭://主機域名/路徑
例如:http://www.baidu.com/123.jpg
常見的URL協議頭(URL類型)
http/https :超文本傳輸協議資源, 網絡資源
在URL前加https://前綴表明是用SSL加密的。 你的電腦與服務器之間收發的信息傳輸將更 加安全。
Web服務器啟用SSL需要獲得一個服務器證書并將該證書與要使用SSL的服務器綁定。 http和https使用的是完全不同的連接方式,用的端口也不一樣,前者是80,后者是443。http 的連接很簡單,是無狀態的
https協議是由SSL+HTTP協議構建的可進行加密傳輸、身份認證的網絡協議 要比http協議安全
ftp :文件傳輸協議
// NSURL OC提供了一個URL處理的一個類 // http // https 加密 // ftp:// // file:// 本地文件 // NSURL 寫入文件 // 1)通過 URLWithString 構建一個NSURL // URLWithString 可以構建本地路徑的URL // 可以構建路徑,調用手機系統的程序 // 打電話 NSURL *url = [NSURL URLWithString:@"tel://10086"]; // 發短信 NSURL *url = [NSURL URLWithString:@"sms://10086"]; // 保存文件到本地 NSURL *url = [NSURL URLWithString:@"file://地址"]; // 將字符串寫入本地 NSString *str = @"xxxxx"; BOOL isOk = [str writeToURL:<#(NSURL *)#> atomically:<#(BOOL)#> encoding:<#(NSStringEncoding)#> error:<#(NSError *__autoreleasing *)#>]; // 第一個參數文件路徑 第二個參數是否利用原子性 第三個編碼標準NSUTF8StringEncoding 最后一個錯誤信息 // 一般寫入文件都要進行判斷是否寫入成功 NSError *error; if (isOk) { NSLog(@"寫入成功"); } else { NSLog(@"%@",&error); }
NSString
// 快速創建字符串 NSString *str = @"xxxx"; // 字符串寫入文本 BOOL isOk = [str writeToFile:@"/User/Apple/Desktop/1.tex" atomically:YES encoding:NSUTF8StringEncoding error:nil]; NSString *str1 = @"abc"; // a 97 NSString *str2 = @"abc"; // A 65 //取出每個字符的ASCII碼值 ,比較ASCII碼值大小 //compare方法比較大小 //compare 默認的區分大小寫的 //compare 這個函數,不能增加條件 // NSComparisonResult result = [str1 compare:str2]; //比較的時候,不區分大小寫,參考字符的個數 NSComparisonResult result = [str1 compare:str2 options:NSCaseInsensitiveSearch|NSNumericSearch]; // switch (result) { case NSOrderedAscending: NSLog(@"str1 < str2 升序"); break; case NSOrderedDescending: NSLog(@"str1 > str2 降序"); break; case NSOrderedSame: NSLog(@"str1 == str2 "); break; default: break; }//地址的比較 // "==" 不能夠判斷字符串是否相等的 //判斷字符串內容真正是否相等,使用是 //isEqualToString: //注意:他是區分大小寫的 if ([str1 isEqualToString:str3]) { NSLog(@"相等"); }else{ NSLog(@"不相等"); } /* 檢測字符串的前綴和后綴 */ NSString *url = @"https://www.baidu.com"; //如何檢測這個字符串是否是一個網址 //http:// https:// // 檢測一個字符串的前綴是否以 http:// 開頭 或者 https:// 開頭 // [str hasprefix:@"要檢測的內容"]; if([url hasPRefix:@"http://"]||[url hasPrefix:@"https://"]){ NSLog(@"是一個網址"); }else{ NSLog(@"這不是一個網址"); } //檢測字符串的后綴 // xxxx.jpg 判斷 字符串的后綴是否是".jpg" // xxxx.png // xxxx.jpeg // xxxx.gif NSString *imgName = @"xxxxx.doc"; // [str hasSuffix:@"帶檢測的后綴"] if([imgName hasSuffix:@".jpg"]||[imgName hasSuffix:@".png"]||[imgName hasSuffix:@".jpeg"]||[imgName hasSuffix:@".gif"]){ NSLog(@"是一個圖片"); }else{ NSLog(@"這不是一個圖片"); }//字符串的查找 // 查找某個字符串在另外一個字符串中首次出現的位置 // 0123456789 //1 @"asdaiosffsdafiosasdfsffitcastasdfasd" //2 @"ios" // 4 3 // 1 rangOfString 2 NSString *str1 =@"asdaiosffsdafiosasdfsffitcastasdfasd"; NSString *str2 =@"cjk"; // 字符串查找 // 查找2 在 1中首次出現的位置 // 如果查找到了,返回2在1中的位置和長度 // 如果查找不到,返回的信息: // location 特別大的數(NSNotFound) 最大的long類型的數 // length 0 // range 結構體變量 NSRange 結構別名 NSRange range = [str1 rangeOfString:str2]; //判斷是否查找到了 if(range.location!=NSNotFound){ //range.location 表示字符串首次出現的位置 //range.length 字符串出現的長度(實質上就是子字符串的長度) NSLog(@"%lu,%lu",range.location,range.length); }else{ NSLog(@"在%@中沒有找到這個字符串%@",str1,str2); }// 字符串的截取 NSString *str = @"http://www.baidu.com"; //1) 從xx位置開始,到最后結束(包含xx這個位置的字符) NSString *str1 = [str substringFromIndex:5]; NSLog(@"str1 = %@",str1); //2) 從開始位置,到xx位置結束(不包含xx這個位置) NSString *str2 = [str substringToIndex:5]; NSLog(@"str2 = %@",str2); //3) 截取一個范圍 range NSRange r1 = {3,4}; NSString *str3 = [str substringWithRange:r1]; NSLog(@"str3 = %@",str3); //字符串的替換 // @"asdfsdafasdfdasdfsa" ----> a 替換成 "*" // @" asdfasfd asdfsadf asdf asdfas asdf asdf asdfa" NSString *str =@"asdfsdafasdfdasdfsa"; // str stringByReplacingOccurrencesOfString:@"源字符串中的內容" withString:@"要替換成新的內容" //把a替換成 * NSString *newStr = [str stringByReplacingOccurrencesOfString:@"a" withString:@"*"]; NSLog(@"newStr = %@",newStr); // 把空格給去掉 str =@" asdfasfd asdfsadf asdf asdfas asdf asdf asdfa"; newStr = [str stringByReplacingOccurrencesOfString:@" " withString:@""]; NSLog(@"newStr = %@",newStr);// 字符串轉各種數值 NSString *str = @"11"; int a = [str intValue]; NSString *str1 = @"12.21"; double b = [str1 doubleValue]; NSString *str2 = @"12.12f"; float c = [str2 floatValue]; //OC的字符串和 C的字符串互相轉換問題 // char* NSString //1) C---->OC對象 char *s = "zhangsanfeng"; printf("%s/n",s); //思路:創建一個OC的字符串對象,用C語言的字符串創建 NSString *str = [NSString stringWithUTF8String:s]; NSLog(@"str = %@",str); //2) OC對象 --> C的字符串 NSString *str2 = @"zbz"; // 把str2 轉 C的字符串 const char *s1 = [str2 UTF8String]; printf("s1 = %s/n",s1);
NSRange
// NSRange的定義typedef struct _NSRange { NSUInteger location; // 位置 NSUInteger length; // 從該位置算起的長度} NSRange;
NSMutableString
// 可變的字符串 NSMutableString *str2 = [NSMutableString stringWithFormat:@"Jack"]; // 在Jack后面加上&Rose [str2 appendString:@"&Rose"]; NSMutableString *str = [NSMutableString string]; //1) appendFormat 格式化的添加字符串 [str appendFormat:@"http://www.baidu.com/%d",100]; //str http://www.baidu.com/100 NSLog(@"%@",str); //2) 刪除字符串一部分內容 [str deleteCharactersInRange:NSMakeRange(3, 4)]; NSLog(@"%@",str); //3) 插入一個字符串 [str insertString:@"p://" atIndex:3]; NSLog(@"%@",str); //4) 替換字符串的一部分內容 [str replaceCharactersInRange:NSMakeRange(11, 5) withString:@"xxxxx"]; NSLog(@"%@",str);// 注意不能這么寫 NSMutableString *str = @"abc";
NSArray
//NSArray特點: // 一旦創建成功,內容不可改變 // 只能存放OC對象 // 1)創建一個空數組 NSArray *arr1 = [NSArray array]; // 2)創建數組,只有一個元素 NSArray *arr2 = [NSArray arrayWithObject:@"1"]; // 3)創建數組,有多個元素 // nil 表示數組賦值結束 // 常見寫法 NSArray *arr3 = [NSArray arrayWithObjects:@"one",@"two",@1, nil]; NSLog(@"arr3 = %@",arr3); // 4)調用對象方法,創建數組 // nil Nil NULL NSNULL NSArray *arr4 = [[NSArray alloc] initWithObjects:@"three",[NSNull null],@"four", nil]; NSLog(@"arr4 = %@",arr4); // 5)用一個數組可以創建另外一個數組 NSArray *arr5 = [NSArray arrayWithArray:arr3]; NSLog(@"arr5 = %@",arr5); // 用簡化的方式,來定義和訪問數組元素 //1)用簡化的方式,定義數組 //格式: @[ 數組元素 ] NSArray *arr = @[@"1",@"one",@"3",@4,@"ONE"];// 數組的常見的方法 NSArray *arr3 = [NSArray arrayWithObjects:@"one",@"two",@1,@"three", nil]; NSLog(@"arr3 = %@",arr3); // 1)獲取數組的長度 count獲取數組的元素的個數 NSLog(@"%ld",arr3.count); // 2)根據下標,獲取下標對應的對象 NSLog(@"%@",[arr3 objectAtIndex:3]); // 3)返回元素的下標 NSUInteger loc = [arr3 indexOfObject:@"three"]; NSLog(@"%ld",loc); // 4)數組中是否包含了某個元素 if([arr3 containsObject:@"four"]){ NSLog(@"包含此元素"); }else{ NSLog(@"不包含"); } // 定義一個數組 NSArray *arr = @[@"one",@"two",@"three",@"four"]; // 對數組進行遍歷 //1) 普通的方式,通過下標訪問 for (int i=0; i<arr.count; i++) { NSLog(@"-> %@",arr[i]); } //2) 快速枚舉法 for循環的增強形式 for (NSString * str in arr) { NSLog(@"---> %@",str); } //3) 使用block的方式,進行訪問 // 數組元素 元素下標 是否停止 //stop:YES 會停止, stop:NO 不會停止 [arr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if(idx == 2){ *stop = YES; //停止 // break; }else{ NSLog(@"idx = %ld,obj = %@",idx,obj); } }]; // 定義一個數組 NSArray *arr = @[@1,@2,@3,@4]; // 1)把數組中的元素用 "-" 連接起來 // [數組 componentsJoinedByString @"分隔符"]; // 1-2-3-4 NSString *str = [arr componentsJoinedByString:@"-"]; NSLog(@"str = %@",str); //2) 給一個字符串,分割成一個數組 // 400-800-12580 //取得 400 12580 800 NSString *str2 = @"400-800-12580"; NSArray *arr2 = [str2 componentsSeparatedByString:@"-"]; NSLog(@"%@",[arr2 firstObject]); NSLog(@"%@",[arr2 lastObject]); NSLog(@"%@",arr2[1]); str2 = @"400-800-12580#400-888-11200"; NSArray *arr3 = [str2 componentsSeparatedByString:@"#"]; NSLog(@"arr3 = %@",arr3); // 第一個電話的每一部分 NSArray *arr4 = [[arr3 firstObject] componentsSeparatedByString:@"-"]; NSLog(@"arr4 = %@",arr4); NSArray *arr5 = [[arr3 lastObject] componentsSeparatedByString:@"-"]; NSLog(@"arr5 = %@",arr5);
NSMutableArray
// 數組的使用 // 1)創建數組 // i. 空數組 NSMutableArray *arr1 = [NSMutableArray array]; NSLog(@"%p",arr1); // ii.創建的時候初始化一個元素 NSMutableArray *arr2 = [NSMutableArray arrayWithObject:@"one"]; // iii.創建數組的時候,初始化多個元素 NSMutableArray *arr3 = [NSMutableArray arrayWithObjects:@"one",@"two",@3,nil]; // IV . 創建一個數組,并且指定長度, NSMutableArray *arr4 = [NSMutableArray arrayWithCapacity:5]; //2) 添加元素 [arr1 addObject:@"fengjie"]; NSLog(@"%p",arr1); //插入元素到指定的位置 [arr1 insertObject:@"zbz" atIndex:0]; //3) 刪除元素 // 根據對象內容刪除 [arr1 removeObject:@"zbz"]; // 根據位置刪除 [arr1 removeObjectAtIndex:1]; // 全部刪除 [arr1 removeAllObjects]; //4) 修改元素 // two --> four [arr3 replaceObjectAtIndex:1 withObject:@"four"]; // four --> five // 更加簡單地方法 arr3[1] = @"five"; NSLog(@"%@",arr3); // 5) 查找元素 BOOL isSearch = [arr3 containsObject:@"four"]; NSLog(@"%d",isSearch); //6) 交換元素 // 1 2 3 4 5 // 5 2 3 4 1 //temp = a[0]; //a[0] = a[len-1]; //a[len-1] = temp; NSMutableArray *arr5 =[NSMutableArray arrayWithObjects:@1,@2,@3,@4,@5, nil]; // 可以交換數組元素 [arr5 exchangeObjectAtIndex:0 withObjectAtIndex:4]; NSLog(@"%@",arr5);
NSDictionary
// NSDictionary 不可變的,一旦創建,內容就不能添加/刪除(不能改動) // 1)創建空字典 NSDictionary *dict1 = [NSDictionary dictionary]; // key value // zs ---> 張三 // ls ---> 李四 // 2) 創建只有一組鍵值對的字典 NSDictionary *dict2 = [NSDictionary dictionaryWithObject:@"zhangsan" forKey:@"zs"]; // 3)創建多組鍵值對的字典 // value值,key值 NSDictionary *dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"k1",@"value2",@"k2", nil]; // 注意; // 字典的key值和value值,都必須是對象 // 4)快速創建一個字典 // @{,,key值:value值,,,}; // key值不能重復: // 如果重復了,也不會報錯 // 如果重復了,最后添加的將不能夠保存到字典中 NSDictionary *dict4 = @{@"zs":@"zhaosi",@"zs":@"zhangsan",@"ls":@"lisi",@"bz":@"banzhang"}; NSLog(@"%@",dict4); // 以%@格式打印字典,控制臺輸出一個{ } // 5)獲取字典的長度 NSLog(@"%lu",dict4.count); // 6)根據key值取出value值 // zs zhaosi // key NSString *str = [dict4 objectForKey:@"zs"]; NSLog(@"str = %@",str); //7) 字典的遍歷問題 // 第一步:獲取所有的key // 第二步:根據key獲取value// for(NSString *key in dict4){// NSLog(@"key = %@,value = %@",key,[dict4 objectForKey:key]);// } // key value stop [dict4 enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { NSLog(@"%@ --> %@",key,obj); }];
NSMutableDictionary
// 1)可變字典的創建 NSMutableDictionary *dict1 = [NSMutableDictionary dictionary]; // 創建空字典 NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithCapacity:3]; // 2)給可變字典添加鍵值對 [dict1 setValue:@"zhaosi" forKey:@"ls"];// 因為key值重復了,所以添加不上 [dict1 setValue:@"lisi" forKey:@"ls"]; // ls [dict1 setValue:@"liuneng" forKey:@"ln"]; NSLog(@"%@",dict1); //3) 刪除// [dict1 removeObjectForKey:@"ls"];// [dict1 removeAllObjects]; NSLog(@"%@",dict1); // 4)修改 // [dict1 setObject:@"zhaosi" forKey:@"ls"]; // 簡寫形式 dict1[@"ls"] = @"xxxxx"; NSLog(@"%@",dict1); // 5)查找 // 獲取所有的key值 NSArray *arr = [dict1 allKeys]; if([arr containsObject:@"ls"]){ NSLog(@"存在ls的key"); } }
NSFileManager
//NSFileManager 用于判斷 NSString *filePath = @"/Users/apple/Desktop/arr.plist"; NSString *filePath2 = @"/"; // 1) 判斷文件是否存在 //創建文件管理對象 //調用defaultManager 創建一個文件管理的單例對象 //單例對象:在程序運行期間,只有一個對象存在 NSFileManager *fm = [NSFileManager defaultManager]; // YES 存在 NO 不存在 BOOL isYES = [fm fileExistsAtPath:filePath]; NSLog(@"-->%d",isYES); if(isYES){ BOOL isDir; // 2) 判斷是否是一個目錄 [fm fileExistsAtPath:filePath isDirectory:&isDir]; if (isDir) { NSLog(@"這是一個目錄"); }else{ NSLog(@"這不是一個目錄"); } } // 3) 判斷文件是否可讀 isYES = [fm isReadableFileAtPath:filePath]; // 4) 是否可寫 isYES = [fm isWritableFileAtPath:filePath2]; // 5) 是否可刪除 isYES = [fm isDeletableFileAtPath:filePath2]; NSLog(@"-->%d",isYES);//創建文件對象 NSFileManager *fm = [NSFileManager defaultManager]; NSString *filePath = @"/Users/apple/Desktop/arr.plist"; NSString *dirPath = @"/Users/apple/Desktop/a"; //1)如何獲取文件的信息(屬性) NSDictionary *dict = [fm attributesOfItemAtPath:filePath error:nil]; NSLog(@"%@",dict); NSLog(@"%@,%@",[dict objectForKey:@"NSFileOwnerAccountName"],dict[@"NSFileOwnerAccountName"]); //2)獲取指定目錄下文件及子目錄 //使用遞歸的方式 獲取當前目錄及子目錄下的所有的文件及文件夾 NSArray *subPaths = [fm subpathsAtPath:dirPath]; //subpathsOfDirectoryAtPath 不是使用遞歸的方式獲取的 subPaths = [fm subpathsOfDirectoryAtPath:dirPath error:nil]; NSLog(@"subPaths = %@",subPaths); //3)獲取指定目錄下的文件及目錄信息(不在獲取后代路徑) subPaths = [fm contentsOfDirectoryAtPath:dirPath error:nil]; NSLog(@"subPaths = %@",subPaths);
NSNumber
int a = 10; int x = 100; float f1 = 3.23f; double d1 = 2.34; // numberWithInt 把int 轉換為 NSNumber NSNumber *intObj = [NSNumber numberWithInt:a]; NSMutableArray *array = [NSMutableArray arrayWithObjects:intObj, nil]; // float ---> NSNumber NSNumber *floatObj = [NSNumber numberWithFloat:f1]; [array addObject:floatObj]; // double ---> NSNumber NSNumber *dObj = [NSNumber numberWithDouble:d1]; //把對象添加到數組中 [array addObject:dObj]; //@(變量名) ---> 把 x 轉換為NSNumber對象 [array addObject:@(x)]; //@數值,把數值包裝成對象 [array addObject:@18]; NSLog(@"array = %@",array); // 數組的第一個元素和第二個元素相加 // array[0]+array[1] //1)取出數組的元素 //2)把數組元素轉換為基本數據類型的數據 NSNumber *n1 = array[0]; int a1 = [n1 intValue]; //獲取對象的整形值 NSNumber *n2 = array[1]; float f2 = [n2 floatValue]; a1 = [array[0] intValue]+[array[1] floatValue]; NSLog(@"%d",a1);
NSValue
//創建一個結構體變量,保存點 // p1 是 CGPoint 類型的結構體變量 CGPoint p1 = CGPointMake(20, 50); NSRect r1 = NSMakeRect(0, 0, 200, 100); //創建數組 NSMutableArray *arr = [NSMutableArray array]; //p1 ---> obj //valueWithPoint 把結構體轉換為NSValue對象 NSValue *pointVal = [NSValue valueWithPoint:p1]; //把對象存放到數組中 [arr addObject:pointVal]; [arr addObject:[NSValue valueWithRect:r1]]; NSLog(@"arr = %@",arr); //取出r1的值 // rectValue 從NSValue對象中,取得NSRect類型的值 NSValue *r1Val = [arr lastObject]; NSRect r2 = [r1Val rectValue]; NSLog(@"%@",NSStringFromRect(r2));typedef struct D{ int year; int month; int day;} MyDate; //MyDate是一個別名// 保存 一個 年月日 // 2015-7-30 MyDate md = {2015,7,30}; // md -----> obj //@encode(MyDate) 作用,把MyDate類型生成一個常量字符串描述 NSValue *val = [NSValue valueWithBytes:&md objCType:@encode(MyDate)]; //定義一個數組,把val存到數組中 NSMutableArray *arr = [NSMutableArray arrayWithObject:val]; //從數組中取出來NSValue對象 //從對象中,取出結構體變量的值 // 傳入一個結構體變量的地址 MyDate tmd; // getValue獲取結構值,保存到結構體變量tmd [val getValue:&tmd]; NSLog(@"%d,%d,%d",tmd.year,tmd.month,tmd.day);
NSDate
//創建一個日期時間對象 //獲取當前時間 NSDate *d1 = [NSDate date]; //0時區時間,北京 東8區 // 當前時間上+8小時,得到的就是現在時間 NSLog(@"%@",d1); //2015-07-30 12:20:25 +0000 //格式化日期 //NSDateFormatter 日期格式化 //2015年07月30日 20:20:25 //2015-07-30 20:22:15 NSDateFormatter *formatter = [NSDateFormatter new]; //設置日期的顯示格式的 // yyyy 表示四位的年份 // MM 表示2位的月份 // dd 表示2位的天數 // HH 表示24小時制得小數 hh - 12小時值 // mm 表示2位的分鐘數 // ss 表示2位的秒數 formatter.dateFormat = @"yyyy年MM月dd日 HH:mm:ss"; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; //格式化日期 NSString *dateStr = [formatter stringFromDate:d1]; NSLog(@"%@",dateStr);NSDateFormatter *formatter = [NSDateFormatter new]; //設置日期的顯示格式的 // yyyy 表示四位的年份 // MM 表示2位的月份 // dd 表示2位的天數 // HH 表示24小時制得小數 hh - 12小時值 // mm 表示2位的分鐘數 // ss 表示2位的秒數 formatter.dateFormat = @"yyyy年MM月dd日 HH:mm:ss"; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; //計算明天的此刻 // 距現在時間 24 小時以后,明天的此刻 NSTimeInterval t = 60*60*24; NSDate *tom = [NSDate dateWithTimeIntervalSinceNow:t]; //計算昨天的時間 NSDate *zuotian = [NSDate dateWithTimeIntervalSinceNow:-t]; //格式化顯示時間 NSString *timeStr = [formatter stringFromDate:zuotian]; NSLog(@"timeStr = %@",timeStr);//日期對象 //2015-07-30 20:22:15 //year month day // NSCalendar 日期類,可以幫我們快速的獲取年月日 時分秒信息 NSDate *d = [NSDate date]; //創建日期的對象 NSCalendar *cal = [NSCalendar currentCalendar]; // cal components:獲取日期的哪些部分 fromDate:日期對象 NSDateComponents *coms = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:d]; NSLog(@"year:%ld,month:%ld,day:%ld",coms.year,coms.month,coms.day);
小知識點:
位枚舉:枚舉值是2的0次方、1次方、2次方...
它的存在是為了有些方法中需要寫入枚舉值,但有時候我們并不需要枚舉這時候可以用0來填寫枚舉值
他的枚舉值可以用“ | ”(或)來一起選擇
解釋:
2 的 0 次方 1 00000001
2 的 1 次方 2 00000010
2 的 2 次方 4 00000100
2 的 3 次方 8 00001000
用“ | ”或正好能把想用的枚舉值都用到 例如用1和2 00000011
新聞熱點
疑難解答