I m目前致力于将目标C中写成的一部法典转换成迅速,我碰到了一条路障。 给我带来麻烦的部分涉及从书记数据中提取财产。
NSMutableArray *extractItems(NSString *path)
{
NSDictionary *data = [NSDictionary dictionaryWithContentsOfFile:path];
NSMutableArray* items = [[NSMutableArray alloc] init];
NSData* bookmark = nil;
NSDictionary* properties = nil;
// Extract items
for(id object in data[@"$objects"])
{
// Reset bookmark
bookmark = nil;
// Extract bookmark data
if([object isKindOfClass:[NSData class]] == YES)
{
bookmark = object;
}
// Extract bookmark from dictionary
if([object isKindOfClass:[NSDictionary class]] == YES)
{
bookmark = [object objectForKey:@"NS.data"];
}
// Skip if no bookmark
if(bookmark == nil)
{
continue;
}
// Extract properties
properties = [NSURL resourceValuesForKeys:@[@"AllPropertiesKey"] fromBookmarkData:bookmark][@"AllPropertiesKey"];
if(properties == nil)
{
// Skip this item
continue;
}
// Create item
Item *item = [[Item alloc] init];
item.path = path;
item.executable = properties[@"_NSURLPathKey"];
item.type = [NSNumber numberWithInt:ItemType];
item.user = extractUserFromPath(path);
item.content = nil;
// Use name from bundle or NSURLNameKey
item.name = [NSBundle bundleWithPath:item.executable].infoDictionary[@"CFBundleName"];
if(item.name.length == 0)
{
item.name = properties[@"NSURLNameKey"];
}
// Skip if there are issues
if (item.name == nil || item.executable == nil)
{
continue;
}
// Add item
[items addObject:item];
}
return items;
}
面临的挑战Im涉及利用资源ValuesForKeys方法开采财产,然后在其中使用NSURLBookmark AllpertiesKey dictionary。