Well, this is what we call stringly typed.
Because the return type of stringByEvaluatingJavaScriptFromString:
is NSString *
, you will either need to stick to using a string or coercing the value into some other (read:more usable) type.
But anyway, stringByEvaluatingJavaScriptFromString:
will return the value of a JavaScript variable to you without a problem.
The way this is accomplished is through the use of an anonymous function (which in this case is self-executing):
NSString *numOfElements = [webView stringByEvaluatingJavaScriptFromString:@"(function() {var elems = document.body.getElementsByTagName(\"u\"); return elems.length;})();"];
//do normal stuff with numOfElements like cast to an int or something cool like that.