更明确一点,当我打开plist编辑器并右键单击时,我可以从随Xcode 6安装的可用列表类型列表中选择一个属性列表类型。如果我可以的话,这将是很好的我的自定义类型出现在此菜单中。我看到Apple for iOS提供的那些是在插件DVTiOSPlistStructDefs.dvtplugin中编译的,它位于Contents / PlugIns中。
答案 0 :(得分:0)
通常当我们加载一个plist文件时,我们会将它读入一个NSDictionary对象(有时候是一个NSArray)
NSDictionary *theDictionary = [[NSDictionary alloc]initWithContentsOfFile:@"aFilePath.plist"];
然后从那里我们可以拉出上面列出的那些类的对象。因此,您需要编写初始化方法,以便从方法或C函数中的一个创建数据对象或结构。
例如
//custom initializer
-(instanceType )initWithDictionary:(NSDictionary *)dictionary{
if (self=[super init]){
self.floatProperty = [[dictionary objectForKey:@"theFloatKey"]floatValue];
self.stringProperty = [dictionary objectForKey:@"theStringKey"];
//etc
}
return self;
}
//or like this for some struct
myDataStruct structCreateFromDictionary(NSDictionary *dictionary) {
myDataStruct result;
result.floatThing = [[dictionary objectForKey:@"theFloatKey"]floatValue];
result->stringPointer = [dictionary objectForKey:@"theStringKey"];
//etc
return result;
}