0

I'm trying to make the entries in my NSMutableDictionary look like this when written to a file:

        <dict>
        <key>Track ID</key><integer>686</integer>
        <key>Name</key><string>Poetic Justice (Feat. Drake)</string>
        <key>Artist</key><string>Kendrick Lamar</string>
        <key>Album</key><string>Good Kid M.A.A.D City-(Deluxe Edition)</string>
        </dict>

Here's what my file looks like now:

        <dict>
        <key>Track ID</key>
        <integer>686</integer>
        <key>Name</key>
        <string>Poetic Justice (Feat. Drake)</string>
        <key>Artist</key>
        <string>Kendrick Lamar</string>
        <key>Album</key>
        <string>Good Kid M.A.A.D City-(Deluxe Edition)</string>
        </dict>

I have tried trimming the whitespace and newlines from the key strings and objects using NSCharacterSet like this

        NSString *trimmedArtistString = [ArtistString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

But that didn't work.
Can this be done?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
  • 2
    Why would you need this? –  Apr 24 '13 at 21:12
  • I'm trying to fix the structure of my file at the point that it gets written so I don't have to go messing with my file parser which already works with the structure that I am trying to achieve. – user2136500 Apr 24 '13 at 21:18
  • 1
    When you call `NSDictionary writeToFile` you have no control over the output. It's only meant to be re-parsed by the `NSDictionary dictionaryWithContentsOfFile:` method. If you wish to write the contents of the dictionary to a file in a specific format then write your own code to write out the file. Don't use `writeToFile:`. – rmaddy Apr 24 '13 at 21:59
  • I figured that might be the case, thanks rmaddy. – user2136500 Apr 24 '13 at 22:15
  • I am trying to reproduce the XML playlist files exported from iTunes, which don't insert a newline. – user2136500 Apr 25 '13 at 00:02

0 Answers0