Apple Sample代碼摘抄-plist文件加載

    // Determine the content of the collection view by reading in the plist "icons.plist",
    // and add extra "named" template images with the help of NSImage class.
    //
    NSBundle		*bundle = [NSBundle mainBundle];
    NSString		*path = [bundle pathForResource: @"icons" ofType: @"plist"];
    NSArray			*iconEntries = [NSArray arrayWithContentsOfFile: path];
    NSMutableArray	*tempArray = [[NSMutableArray alloc] init];
    
    // read the list of icons from disk in 'icons.plist'
    if (iconEntries != nil)
    {
        NSInteger idx;
        NSInteger count = [iconEntries count];
        for (idx = 0; idx < count; idx++)
        {
            NSDictionary *entry = [iconEntries objectAtIndex:idx];
            if (entry != nil)
            {
                NSString *codeStr = [entry valueForKey: KEY_IMAGE];
                NSString *iconName = [entry valueForKey: KEY_NAME];
                
                OSType code = UTGetOSTypeFromString((CFStringRef)codeStr);
                NSImage *picture = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(code)];
                [tempArray addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       picture, KEY_IMAGE,
                                       iconName, KEY_NAME,
                                       nil]];
            }
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章