0

I'm trying to use the moveItemAtPath method, but I am getting an error about using an interface.

> #import <Cocoa/Cocoa.h>
> 
> int main(int argc, const char * argv[]) {
>     @autoreleasepool { 
>         NSFileManager *manage = [NSFileManager defaultManager];
>         NSString *a = @"folder1/file.txt";
>         NSString *b = @"folder2/file.txt";
>         NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/%@", a];
>         NSString *newPath = [NSHomeDirectory() stringByAppendingFormat:@"/%@", b];
> 
>         [manage moveItemAtPath:path toPath:newPath];
>     }
>     return NSApplicationMain(argc, argv); }

I don't get how looking at the UIViewController , as explained in here https://stackoverflow.com/a/12696856 is supposed to help.

This resource does not show an example of what needs to be imported https://www.techotopia.com/index.php/Working_with_Files_in_Objective-C#Moving.2FRenaming_a_File

eh1412
  • 43
  • 1
  • 2
  • 8
  • 1
    `moveItemAtPath:toPath: doesn't exist. Use `moveItemAtPath:toPath:error:` or `moveItemAtURL:toURL:error:` instead. – Willeke May 27 '22 at 21:25
  • Oh, are you saying the error is not optional? – eh1412 May 27 '22 at 21:45
  • 1
    It's not because you put `nil` in a parameter, that it can be omitted! – Larme May 28 '22 at 06:33
  • The error parameter must be supplied, but you can pass null value if you really don’t want to know why it failed (if it fails). https://developer.apple.com/documentation/foundation/nsfilemanager/1413529-moveitematpath – Rob May 28 '22 at 07:42
  • The parameter names are part of the method name. See 'Methods Can Take Parameters' in [Programming with Objective-C](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW5) – Willeke May 28 '22 at 07:49

0 Answers0