开发者

Anyway to find out the class that's associated to this variable?

I want to find out the type of the data that i am sending throu开发者_如何学Cgh 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


You can use CFGetTypeID() for this:

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

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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜