// 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]];
}
}
}
Apple Sample代码摘抄-plist文件加载
最新推荐文章于 2022-05-11 15:03:45 发布