开发者

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

开发者 https://www.devze.com 2022-12-14 12:17 出处:网络
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 NSMutata

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

精彩评论

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

关注公众号