Can I cast a NSConcreteValue to its objCType?

335 Views Asked by At

I'm writing a SIMBL plugin for Chrome and I'm getting a particular instance with an unexposed type which is written in C as a NSConcreteValue. I cannot unwrap it or perform selectors on it, but I can get its type string with [myInstance objCType].

The type I'm talking about is GURL.

Here is some code:

NSArray* tabViews = [tabStripController performSelector:@selector(tabViews)];

for (id tabView in tabViews) {

    id tabController = [tabView valueForKey:@"controller_"];

    id tabTitle = [tabController valueForKey:@"toolTip"];

    id tabUrl =  [tabController valueForKey:@"url_"];

    NSLog(@"%@", tabTitle);
    NSLog(@"%s", [tabUrl objCType]);
}

The tab title is not an issue since it's a NSString.

[tabUrl objCType] returns this:

{GURL={basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >={__compressed_pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep, std::__1::allocator<char> >={__rep=(?={__long=QQ*}{__short=(?=Cc)[23c]}{__raw=[3Q]})}}}B{Parsed={Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}^{Parsed}}{unique_ptr<GURL, std::__1::default_delete<GURL> >={__compressed_pair<GURL *, std::__1::default_delete<GURL> >=^{GURL}}}}

GURL has a property called spec_ which I would like to access to get the ASCII string of the GURL instance.
Here is GURL: https://chromium.googlesource.com/chromium/src/+/lkgr/url/gurl.h

Is the objCType string of any help?

1

There are 1 best solutions below

0
Amy Worrall On

NSConcreteValue is a private subclass of NSValue.

I suggest you cast to NSValue and then use the NSValue public API.

If you want to be extra safe, surround it with if ([myObj isKindOfClass:[NSValue class]]) {}.

Regarding pulling C++ types from NSValue, this answer shows how to do it. Essentially you just make your variable and then call getValue:&myVar as normal. You will, of course, have to compile as Objective-C++ (use a .mm extension), and import the relevant header.