OC学习之XML属性列表归档

#import <Foundation/Foundation.h>


int main(int argc, const char * argv[])

{


    @autoreleasepool {

        

        //写配置文件

        NSDictionary *glossary =

        [NSDictionary dictionaryWithObjectsAndKeys:

         @"A class defined",

         @"Class",

         @"A Function defined",

         @"Function",

         @"A Variable defined",

         @"Variable",nil];

        

        if([glossary writeToFile:@"glossary" atomically:YES] == NO )

        {

            NSLog(@"Save to file failed!");

            

        }

        //读配置文件

        NSDictionary *glossaryRead ;

        glossaryRead = [NSDictionary dictionaryWithContentsOfFile:@"glossary" ];

        for (NSString *key in glossaryRead ) {

            NSLog(@" %@:%@",key, [glossaryRead objectForKey:key]);

        }

        

        

    }

    return 0;

}

XML 文件:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Class</key>

<string>A class Defined</string>

<key>Function</key>

<string>A Function Defined</string>

<key>Variable</key>

<string>A Variable defined</string>

</dict>

</plist>

结果:

2013-09-12 10:28:17.359 Test_File[527:303]  Variable:A Variable defined

2013-09-12 10:28:17.360 Test_File[527:303]  Function:A Function defined

2013-09-12 10:28:17.361 Test_File[527:303]  Class:A class defined




你可能感兴趣的:(oc,plist,XML归档)