Nat! bio photo


Senior Mull.

Twitter RSS


Foundation Curiosity: NSSet as a property list

Why is it, that you can print NSSet as a property list, but you can't parse it ?

//  Coded by Nat! on 4.11.10, Mulle KybernetiK
#import <Foundation/Foundation.h>

int   main( int argc, char **argv) 
   NSAutoreleasePool      *pool;
   NSString               *s;
   NSSet                  *set;
   NSData                 *data;
   NSPropertyListFormat   format;
   id                     plist;   

   pool  = [NSAutoreleasePool new];
   set   = [NSSet setWithObjects:@"VfL", @"Bochum", @"1848", nil];
   s     = [set description];
   data  = [s dataUsingEncoding:NSUTF8StringEncoding];
   plist = [NSPropertyListSerialization 

   NSLog( @"plist %@ could %sbe parsed.", set, [plist isEqual:set] ? "" : "NOT ");

   [pool release];
   return( 0);
[Switching to process 48017]
2010-11-04 21:21:25.906 SetAsPlist[48017:a0f] plist {(
)} could NOT be parsed.


A photo of Ching-Lan HUANG

From: Ching-Lan HUANG

For serializing and deserializing, only NSString, NSDictionary, NSArray, and NSData are supporting old-school OpenStep ASCII format. (No NSSet)

A photo of Nat!

From: Nat!

Yeah, well the point was that for serializing there seems to be support (at least when it concerns the root NSSet) as the dox say for -description:

Returns a string that represents the contents of the set, formatted as a property list.

So why didn't they go that extra mile to parse it ?

A photo of ZNeK

From: ZNeK

Because it's no strict requirement, I guess. In fact, you can initialize an NSSet with an NSArray, which can be parsed from a property list and the only thing possible because there's no property list representation for sets.

A photo of Nat!

From: Nat!

I marked the identifying property list characters in the output more prominently (red).


There is a distinct representation for NSSet, it's just not parseable.

A photo of G3ntlem6n

From: G3ntlem6n

Hey, Nat! This is Dirk T.! Nice to read you again.

I ran into the same problem and was really puzzled as I had implemented binary plist generation in Java for a client and found that core foundation indeed has an implementation (and format definition) for CFSets in binary plists (link above e.g. in function __CFBinaryPlistCreateObject2).

Neither NSPropertyListSerialization nor CFPropertyListCreateData encode sets (but return no error).

Should we report a bug to have it fixed?

Greetings form Bonn,


A photo of Nat!

From: Nat!

Hi Dirk

long time no see.

I you like, report it. I have come to the personal conclusion that doing volunteer work for big corporations, is not what I want to do. :)



Post a comment

All comments are held for moderation; basic HTML formatting accepted.

E-mail: (not published)