Re: createDirectoryAtPath problems
Re: createDirectoryAtPath problems
On Wed, Feb 05, 2003 at 02:09:59PM +1100, Mathew Peterson wrote:
>
bool i;
Cocoa uses BOOL, not bool. Not that it's likely to make any
difference, but I like to use the appropriate types - bool for C++,
Boolean for Carbon and BOOL for Cocoa.
>
NSString *directoryLocation = [[NSString alloc]
>
initWithFormat:@"~/Library/Application Support/DevKit/"];
If there's no format replacement occurring, there's no need to use
initWithFormat. I remember shuddering when I came back to some of my
early Java code where I had written things like:
String string = new String("hi there");
This is redundant: the "" syntax creates a java.lang.String, just like
the @"" syntax creates a constant NSString *. There is no need to
invoke any methods on it, and a @"" string can be used as the target
for method invocations itself.
>
[directoryLocation stringByExpandingTildeInPath];
NSStrings are not mutable, hence their distinction from
NSMutableStrings. This code does expand the tilde, but
>
NSFileManager *man = [NSFileManager defaultManager];
>
i = [man createDirectoryAtPath:directoryLocation attributes:nil];
>
NSLog(@"%@", i);
>
>
It keeps returning (null). What am i doing wrong?
You only use %@ for printing object types, for a boolean cast to int
and print with %d, like NSLog(@"%d", (int)i);
What you want is:
NSString *dir = [@"~/Library/Application Support/DevKit"
stringByExpandingTildeInPath];
BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath: dir
attributes: nil];
Calling a boolean variable 'i' is probably not a good idea either as
it's used the world over for array indices...
Would definitely suggest you read at least one introductory Cocoa book
before proceeding further... it'll save you lots of painful beating
your head against the computer screen. :-)
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.