Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

iphone - plist in Xcode creation

When I am creating a simple application for plist shown in below link:

http://iosdevelopertips.com/data-file-management/reading-a-plist-into-an-nsarray.html

When I am debugging it.. I am getting path of my plist file. But when I am using the following statement

// Build the array from the plist  
NSMutableArray *array2 = [[NSMutableArray alloc] initWithContentsOfFile:path];

I don't get any value in array2... What could be the problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is the final solution that i got for plist....

When u are creating your plist file with first element as Array.. then its XML Contents will be as below:

<?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>Root</key>
    <array>
        <string>Firecracker</string>
        <string>Lemon Drop</string>
        <string>Mojito</string>
    </array>
</dict>
</plist>

Here you are having unnecessary tag instead of which we should have as your root element must be Array... because u are taking in NSMutableArray object...

so your plist file must be like this

<?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">
    <array>
        <string>Firecracker</string>
        <string>Lemon Drop</string>
        <string>Mojito</string>
    </array>
</plist>

i have checked that its working fine....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...