2012-02-07 73 views

回答

3

您可以创建项目文件上右键点击属性列表中的文件,选择新的文件,并选择资源,这样的 -

enter image description here

enter image description here

您还可以创建通过代码属性列表文件像这样 -

创建一个新文件 -

#define FilePath    [@"~/Documents/Demo.plist" stringByStandardizingPath] 

NSArray *array = [NSArray arrayWithObjects:obj1,obj2,obj3,nil]; 
NSData *data = [NSPropertyListSerialization dataFromPropertyList:array format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; 
[data writeToFile:FilePath atomically:YES]; 

要阅读plist文件 -

NSData *data = [NSData dataWithContentsOfFile:FilePath]; 
NSPropertyListFormat format; 
NSArray *array = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:&format errorDescription:nil]; 

obj1 = [array objectAtIndex:0]; 
obj2 = [array objectAtIndex:1]; 
obj3 = [array objectAtIndex:2]; 
+0

感谢您的回复,它非常有用。 – 2012-02-07 04:09:19

+0

如果答案可以帮助你,那么你应该接受它,这样它也可以对其他用户有所帮助。 – saadnib 2012-02-07 04:18:57

0

在Xcode,

右键 - >新文件 - >资源选项卡 - >属性列表文件。

+0

感谢您的回复...... – 2012-02-07 04:07:14

+0

@SampathKumar。 Wlecome。接受它,如果它解决您的问题 – Vignesh 2012-02-07 04:08:55

-2

聪明人曾说:
要知道答案,我们必须先知道这个问题。

阅读this.希望这是你要找的。

编辑:智者,我的意思是我自己。

+0

感谢您的回复... – 2012-02-07 04:07:07

+0

不客气。如果它很有用,请注意它。 – Andonuts 2012-02-07 04:07:44

+0

尽管这可能在理论上回答这个问题,但[这将是更可取的](http://meta.stackexchange.com/q/8259)在这里包括答案的基本部分,并提供了供参考的链接。 – jjnguy 2012-02-07 05:49:01