Baby Groot
Baby Groot

Reputation: 4279

unable to get resources path

I have added searchView.js by dragging and dropping into the Resources folder. I selected the "Copy items into destination group's folder(if needed)".

Still, I get path as nil during compilation, what should I do?

Code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"searchWebView" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];

Upvotes: 0

Views: 435

Answers (1)

Erik B
Erik B

Reputation: 42614

If the file is named searchView.js then your code should probably be:

NSString *path = [[NSBundle mainBundle] pathForResource:@"searchView" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];

Upvotes: 1

Related Questions