I am trying to parse a URL query component to an unsigned integer. When trying to cast the string extracted from the URL (an NSTaggedPointerString), to unsigned integer, the program crashes with
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString unsignedIntegerValue]: unrecognized selector sent to instance XXX
My application:openURL:options: method in my AppDelegate is below:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
NSMutableDictionary *queryItemDict = [NSMutableDictionary dictionaryWithCapacity:components.queryItems.count];
for (NSURLQueryItem *queryItem in components.queryItems) {
[queryItemDict setObject:queryItem.value forKey:queryItem.name];
}
if ([[queryItemDict allKeys] containsObject:@"selectedSection"]) {
NSUInteger selectedSection = 0;
NSLog(@"%@",[[queryItemDict objectForKey:@"selectedSection"] class]);
selectedSection = [[queryItemDict objectForKey:@"selectedSection"] unsignedIntegerValue];
}
return YES;
}
I have tested this in a blank iOS Xcode project and registered the URL scheme "test" like so
My test url is test://selectedSection=0
.
I can upload the sample project if needed, but the above two steps are all that is needed to reproduce. Am I not casting the NSString to unsigned integer correctly?