Objective-c自學筆記(3)-資料集合的使用

來源:互聯網
上載者:User


按書上的例子敲了敲:


#import <Foundation/Foundation.h>int main(int argc,const char *argv[]){    @autoreleasepool {        //聲明檔案管理對象        NSFileManager *manager;        //由defaultManager方法建立NSFileManager初始化        manager = [NSFileManager defaultManager];        //聲明要遍曆路徑        NSString *home;        //初始化要遍曆的目錄:使用者根目錄        home = [@"~" stringByExpandingTildeInPath];        //聲明檔案遍曆對象        NSDirectoryEnumerator *direnum;        //初始設定檔案遍曆對象,用檔案目錄對象home作參        direnum = [manager enumeratorAtPath:home];        //可變列表來儲存遍曆的檔案        NSMutableArray *files;        //初始化大小設定為42        files = [NSMutableArray arrayWithCapacity:42];        //枚舉迭代的對象        NSString *filename;        //使用迭代對象的方法來逐個遍曆枚舉中的所有元素        while(filename =[direnum nextObject]){            //判斷檔案是否是jpg格式的檔案            if([[filename pathExtension] isEqualTo:@"jpg"]){                //將檔案名稱添加到列表中                [files addObject:filename];            }        }        //聲明檔案清單枚舉        NSEnumerator *fileenum;        //初始化枚舉對象        fileenum = [files objectEnumerator];        //枚舉遍曆所有元素        while (filename=[fileenum nextObject]) {            //列印資訊            NSLog(@"%@",filename);        }    };//autoreleasepool    return 0;}//main

輸出


2015-01-27 23:00:11.181 04.01 Shapes-Inheritance[449:9009] Desktop/psb.jpg2015-01-27 23:00:11.194 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/15.jpg2015-01-27 23:00:11.194 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/19.jpg2015-01-27 23:00:11.194 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/22.jpg2015-01-27 23:00:11.195 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/24.jpg2015-01-27 23:00:11.195 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/4.jpg2015-01-27 23:00:11.195 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/QPR.numbers/preview-micro.jpg2015-01-27 23:00:11.195 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/QPR.numbers/preview-web.jpg2015-01-27 23:00:11.196 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/QPR/QPR.numbers/preview.jpg2015-01-27 23:00:11.196 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/11.jpg2015-01-27 23:00:11.196 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/21.jpg2015-01-27 23:00:11.196 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/7.jpg2015-01-27 23:00:11.215 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/Burnley.numbers/preview-micro.jpg2015-01-27 23:00:11.215 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/Burnley.numbers/preview-web.jpg2015-01-27 23:00:11.215 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/伯恩利/Burnley.numbers/preview.jpg2015-01-27 23:00:11.216 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/10.jpg2015-01-27 23:00:11.216 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/14.jpg2015-01-27 23:00:11.216 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/19.jpg2015-01-27 23:00:11.217 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/2.jpg2015-01-27 23:00:11.217 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/21.jpg2015-01-27 23:00:11.217 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/4.jpg2015-01-27 23:00:11.218 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/7.jpg2015-01-27 23:00:11.218 04.01 Shapes-Inheritance[449:9009] Documents/aodci/球員資訊/切爾西/chelsea.numbers/preview-micro.jpg


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.