I have two lines of code in the applicationDidFinishLaunching function:
NSString *targetFilePath = @"/Users/bob/Documents/About_Stacks.pdf";
NSURL *targetFileURL = [NSURL initFileURLWithPath:targetFilePath];
and I am getting the warning (title) in the second line...
I have no idea what I am doing wrong. This is an absurdly simply application... I have read other posts about reordering methods, but I am using classes provided by NS, nothing of my own.
Any advice would be much appreciated.
Thanks.
initFileURLWithPath: is an instance method, not a class method, so you have to create an instance of the class first with alloc. So:
NSString* targetFilePath = @"/Users/bob/Documents/About_Stacks.pdf";
NSURL* targetFileURL = [[NSURL alloc] initFileURLWithPath:targetFilePath];
If you want to use the convenience method, use fileURLWithPath:, so:
NSURL* targetFileURL = [NSURL fileURLWithPath:targetFilePath];
You have to alloc an NSURL first.
NSURL *targetFileURL = [[NSURL alloc] initFileURLWithPath:targetFilePath];
If the method starts with "init", it means it should be called on an allocated instance, not on the class itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With