views:

36

answers:

2

I want to find out the type of the data that i am sending through a send function through gamekit. Basically i am storing that data in CFPropertyListRef. dataReceived is of type NSMutatableData.

- (void) receiveData:(NSMutableData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context {
    // Read the bytes in data and perform an application-specific action.
    [dataReceived setData:data];

if([dataReceived length]> 0 ) {
    CFStringRef errorString;
    CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, (CFDataRef)dataReceived, kCFPropertyListMutableContainers, &errorString);
   }

My goal is to find out if plist is of type NSDictionary, since i would like to handle that data appropriately

+2  A: 

You can use CFGetTypeID() for this:

if(CFDictionaryGetTypeID() == CFGetTypeID(plist))
  // do something

If you prefer Objective-C, have a look at NSPropertyListSerialization.

sbooth
A: 

You can do this, but that’s not to say you should – a property list can have either a dictionary or an array as its top-level element. What do you want to special-case a dictionary for?

Ciarán Walsh
i want to differentiate between a string and nsdictionary that it's recieving within that method. so i can store the NSDictionary and not the string that i am receiving. it's mainly for validation process
Frank
I would say that the contents of the data should be known given the context. It looks like this is data you’re sending – you could perhaps consider making the top-level object always be a dictionary with a ‘content’ key for the array/dictionary data, and then another key (say, ‘name’) specifying what kind of information is being passed.
Ciarán Walsh