I want to send a plist object by email in an XML test format.
What kind of code (preferably simple) should I write after this one:
NSString *xmlString;
NSDictionary *borrowed = @{@"Reader": @"Ryan Shaw",
@"Books": @[ @{@"Title": @"The Godfather",
@"Author": @"Mario Puzo",
@"Date": @"2014-04-08T13:36:33Z"},
@{@"Title": @"Adventures of Huckleberry Finn",
@"Author": @"Mark Twain",
@"Date": @"2014-04-08T13:36:33Z"} ]
};
to have in result xmlString contain the following value:
@"<dict>
<key>Reader</key>
<string>Ryan Shaw</string>
<key>Books</key>
<array>
<dict>
<key>Title</key>
<string>The Godfather</string>
<key>Author</key>
<string>Mario Puzo</string>
<key>Date</key>
<date>2014-04-08T13:36:33Z</date>
</dict>
<dict>
<key>Title</key>
<string>Adventures of Huckleberry Finn</string>
<key>Author</key>
<string>Mark Twain</string>
<key>Date</key>
<date>2014-04-08T13:36:33Z</date>
</dict>
</array>
</dict>"
Is there any iOS framework able to do this, or should I write the parser myself or use a third party library?
The missing code is as follows:
NSError *error;
NSData *xmlData = [NSPropertyListSerialization dataWithPropertyList:borrowed
format:NSPropertyListXMLFormat_v1_0
options:0
error:&error];
if ( !error )
xmlString = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
There is no need for any special framework to be linked in.