views:

29

answers:

1

There is always a pre-written function at AppDelegate:

(NSString *)applicationSupportDirectory {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
    return [basePath stringByAppendingPathComponent:@"SyncFile"];
}

However, I can't call this method outside this class:

id _appDelegate = (SyncFile_AppDelegate *)[[NSApplication sharedApplication] delegate];
NSLog(@"%@", [_appDelegate applicationSupportDirectory]);

The compiler warned me that it can't find method applicationSupportDirectory... Does anyone know what's wrong with my code? Thank you very much!

+3  A: 

Don't forget to #import "SyncFile_AppDelegate.h"

Dave DeLong
Without the header imported, the compiler, while compiling the code you're calling the method from, will not have heard of this method—hence the warning. The header tells the compiler about it, but only when you import it, as the compiler only reads the contents of headers that you import (or that are imported by other headers that you import, or that are imported by other headers that are imported by other headers … etc.).
Peter Hosey
Thanks, but I did include it. I still can't find what's wrong so I declare a new NSString object to record it and share with different classes...
Frost