working on a program from the Kochan book
here is my test file which i called prog16.6.m
the program compiled with some warning messages. here are the warning messages i am getting when i compiled the program in terminal
and here is the output i get when i try to run the program from terminal
any help would be appreciated
here is my test file which i called prog16.6.m
Code:
// implement a basic copy utiltity
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSProcessInfo.h>
#import <stdio.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *NSFm;
NSString *source, *dest;
BOOL isDir;
NSProcessInfo *proc = [NSProcessInfo processInfo];
NSArray *args = [NSProcessInfo arguments];
NSFm = [NSFileManager defaultManager];
// check for two arguments on the command line
if ([args count] != 3) {
printf ("Usage: %s src dest\n", [[proc processName] UTF8String]);
return 1;
}
source = [args objectAtIndex: 1];
dest = [args objectAtIndex: 2];
// make sure the source file cna be read
if ([NSFm isReadableFileAtPath: source] == NO) {
printf ("Can't read %s\n", [source UTF8String]);
return 2;
}
// see if the destination file is a directory
// if it is, add the source to the end of the destination
[NSFm fileExistAtPath: dest isDirectory: &isDir];
if (isDir == YES)
dest = [dest stringByAppendingPathComponent:
[source lastPathComponent]];
// remove the destination file if it already exists
[NSFm removeFilePath: dest handler: nil];
// okay, time to perform the copy
if ([NSFm copyPath: source toPath: dest handler: nil] == NO) {
printf ("Copy failed!\n");
return 4;
}
printf ("Copy of %s to %s succeeded!\n", [source UTF8String],
[dest UTF8String]);
[pool release];
return 0;
}
the program compiled with some warning messages. here are the warning messages i am getting when i compiled the program in terminal
Code:
james-collinss-macbook-pro:prog16 jamescollins$ gcc -framework Foundation prog16.6.m -o prog16.6
prog16.6.m: In function main:
prog16.6.m:18: warning: NSProcessInfo may not respond to +arguments
prog16.6.m:18: warning: (Messages without a matching method signature
prog16.6.m:18: warning: will be assumed to return id and accept
prog16.6.m:18: warning: ... as arguments.)
prog16.6.m:42: warning: NSFileManager may not respond to -fileExistAtPath:isDirectory:
prog16.6.m:50: warning: NSFileManager may not respond to -removeFilePath:handler:
and here is the output i get when i try to run the program from terminal
Code:
james-collinss-macbook-pro:prog16 jamescollins$ ./prog16.6
2008-05-01 10:50:27.925 prog16.6[273:10b] *** +[NSProcessInfo arguments]: unrecognized selector sent to class 0xa0381f00
2008-05-01 10:50:27.928 prog16.6[273:10b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSProcessInfo arguments]: unrecognized selector sent to class 0xa0381f00'
2008-05-01 10:50:27.928 prog16.6[273:10b] Stack: (
2479333963,
2427334907,
2479363338,
2479356492,
2479356690
)
Trace/BPT trap
any help would be appreciated