3

When debugging in XCode, the debugger is telling me that the NSDictionary object contains 1 key/value pair. When the debug console prints the description of the key/value pair is shows:

Printing description of testdictionary:
{
    "Unknown (<1809>)" = <000000ff>;
}

I want to extract both the <1809> and the <000000ff>. I have tried both the valueForKey and objectforKey methods as described elsewhere on this site. But I think I am having difficulty understanding what is the key and what is the value here.

For example, is "Unknown (<1809>)" the key? Or is "<1809>" the key? Or is 1809 the key?


Thanks Tim for the reply.

The NSDictionary comes from the CoreBluetoothFramework the didDiscoverPeripheral: method is called and passes advertising data into an NSDictionary called "advertisementData".

This dictionary contains all sorts of stuff like the advertising channel and device name. However, I am trying to extract just the advertising data from "advertisementData". I used the key provided by corebluetooth "CBAdvertisementDataServiceDataKey" like this:

NSData* information;
information = [advertisementData objectForKey:CBAdvertisementDataServiceDataKey];

I was declaring "information" as an NSDictionary* object before. But changed it to NSData* after some more reading on Apples documentation. The result is the same. The debugger says that it contains a key/value pair as follows:

"Unknown (<1809>)" = <000000ff>;

Thanks again.

Nik

Nik The Greek
  • 33
  • 1
  • 4

2 Answers2

4

When you do not know the keys that are present in the dictionary, for example, because the key-value pairs come from an external source, you can use enumerateKeysAndObjectsUsingBlock: method to go through all key-value pairs present in the dictionary:

[testdictionary enumerateKeysAndObjectsUsingBlock::^(id key, id object, BOOL *stop) {
    NSLog(@"The key is %@", key);
    NSLog(@"The value is %@", object);
}];
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • dasblinkenlight. That's very helpful thanks. From this, it confirms the keys and objects as follows: 2013-09-21 08:09:53.504 cB-OLP425[1091:60b] The key is Unknown (<1809>) 2013-09-21 08:09:53.506 cB-OLP425[1091:60b] The value is <000000ff> – Nik The Greek Sep 21 '13 at 15:12
  • @NikTheGreek You can set a breakpoint in the debugger, and examine the type of the key. It does not look like it`s `NSString`. – Sergey Kalinichenko Sep 21 '13 at 15:15
  • dasblinkenlight. The dubugger says the object is of type _NSInlineData*. That is interesting since its not what I was expecting according to Apple'd documentation. – Nik The Greek Sep 21 '13 at 15:19
  • @NikTheGreek Perfect! You may want to ask a separate question explaining what you did, what you expected to happen, and what happened instead. – Sergey Kalinichenko Sep 21 '13 at 15:39
  • dasblinkenlight. That's a good idea. Thank you for the help! Nik – Nik The Greek Sep 21 '13 at 15:42
  • dasblinkenlight. It is a strange one. The NSInlineData type is not documented anywhere. Google returns 0 results, even. I'll mark this one as finished and come back with some more specifics. Thanks again. Nik – Nik The Greek Sep 21 '13 at 16:46
  • _NSInlineData is one of the many specialized immutable NSData subclasses. Treat it just like NSData. – Catfish_Man Oct 23 '13 at 17:14
0

I've never seen this before so this is nothing more than an educated guess:

The dictionary may have been casted from CFDictionaryRef, in which case both the key and value are const void * (instead of NSObject). The key might have been some Core Foundation type holding a file descriptor (hence 1809). The value could be a pointer (or an integer casted to a "pointer": (void *)32).

You should try and find out where the dictionary originates from, because it's the only thing that's going to give you any valuable information.


Update: the docs state that the value of CBAdvertisementDataServiceDataKey is a dictionary. The keys are CBUUID objects, representing CBService UUIDs and the values are NSData objects. (1)

cutsoy
  • 10,127
  • 4
  • 40
  • 57
  • Thanks Tim, I updated my post above with some more information about where the NSDictionary comes from. – Nik The Greek Sep 21 '13 at 14:14
  • Yes to me that means "Unknown (<1809>)" is the CBService UUID and <000000ff> is the NSData object. However, extracting the NSData object is appearing problematic using the method that dasblinkenlight suggested above. – Nik The Greek Sep 21 '13 at 15:07