I’ve got a link that I’m scanning in a QR Code scanner in another view, which is then saved to Core Data. The entity in which I’m saving it is called “BarCode”, with the attribute, “number”. The result of the fetch that you will see in a minute is the proper url from the QR Code scan. I just get an error like the one I listed in the title. What it literally says is this: -[BarCode length]: unrecognized selector sent to instance 0x210645e0.
I have this block that I’m executing, which also throws the error:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"BarCode"];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"number" ascending:NO];
request.sortDescriptors = @[sortDescriptor];
NSError *error = nil;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSString *currentURL = [[self.managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:indexPath.row];
if (error) {
NSLog(@"error fetching data %@ %@", error, error.userInfo);
}
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
I understand that the conversion from NSArray and then into NSString is causing the error, as it’s “unrecognized”. But I did a bit of research, and found that the “lenght” property within the error has to do with something in NSURLRequests class, but I’m brand new to the class, so I don’t know how I need to rewrite this block.
I tried searching around a bit, but I couldn’t find an example that involved an NSFetchRequest, and a NSURLRequest.
I really hope that somebody will have some insight on here. Thanks!
Your
currentURLwill hold an instance of aNSManagedObjectsubclass, not anNSString. You are missing several lines of code:You are getting the error
-[BarCode length]: unrecognized selector sent to instance 0x210645e0because[NSURL URLWithString:currentURL]assumes currentURL is a string, andNSURLattempts to do some string validations.