0

Premise: I'm a newbie of Swift.

I was trying to load into an array (called 'RootArray') the content of a plist file called fields.plist.

This is the fields.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "..." "...">
<plist version="1.0">
<array>
    <array>
        <string>Question number one</string>
        <dict>
            <key>783612</key>
            <string>Option number one 1</string>
            <key>234739</key>
            <string>Option number two 1</string>
            <key>346837</key>
            <string>Option number three 1</string>
        </dict>
    </array>
    <array>
        <string>Question number two</string>
        <dict>
            <key>928732</key>
            <string>Option number one 2</string>
            <key>263127</key>
            <string>Option number two 2</string>
            <key>332877</key>
            <string>Option number three 2</string>
        </dict>
    </array>
</array>
</plist>

How can I get an array from this? Thank you!

Mark Wood
  • 1
  • 1
  • Checking about "what's a way to store data locally in a command-line swift program". Found this comment: `"Command line tools do use the Bundle structure: in other words, Bundle.main returns a valid bundle for the directory containing the command line executable. Bundle.main.resourceURL returns the url for the parent directory. Bundle.main.pathForResource("file", ofType:"xyz") would return a valid path provided file.xyz is copied into the same directory as the command line tool"`. https://stackoverflow.com/questions/38422467/getting-path-for-resource-in-command-line-tool – mugx Dec 28 '17 at 17:25
  • There is no solution for a command-line app: https://stackoverflow.com/a/34120607/2450755 – mugx Dec 28 '17 at 17:31
  • Actually you can embed an `info.plist` in a command line tool, so you could add your data to info.plist, but this feels like a *heck of a hack*. – vadian Dec 28 '17 at 17:49

1 Answers1

0

Checking about "what's a way to store data locally in a command-line swift program". Found this comment: "Command line tools do use the Bundle structure: in other words, Bundle.main returns a valid bundle for the directory containing the command line executable. Bundle.main.resourceURL returns the url for the parent directory. Bundle.main.pathForResource("file", ofType:"xyz") would return a valid path provided file.xyz is copied into the same directory as the command line tool"

Mark Wood
  • 1
  • 1