Why is this crashing?
NSArray *domain = [webView.request.URL.absoluteString componentsSeparatedByString:@"/"];
NSString *str1 = [domain objectAtIndex:2];
This is the error I get:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 2 beyond bounds [0 .. 0]'
I am able to use objectAtIndex:0 just fine.
The error talks about an array with zero elements. The one you’re thinking about contains more than zero elements. Are you sure you’re looking at the right thing? Also, if you’re calling that code more than one time, it might be the case that once it uses one value, and another on the next run.
Put a breakpoint at that line and see what the value of
domainis on each iteration.