0

I need to write a Mac project that can localize the annotation of the method and property in .h file.

I can use the code

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:YES];
[panel setMessage:@"Import one or more files or directories."];
[panel setCanChooseDirectories:YES];
[panel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]];
[panel setAllowedFileTypes:[NSArray arrayWithObjects:@"h", nil]];

[panel beginWithCompletionHandler:^(NSInteger result) {

    if (result == NSFileHandlingPanelOKButton)
    {
        NSArray *urls = [panel URLs];
        NSLog(@"urls : %@",[urls description]);
    }
}];

to get the URLs of the files.

But I can't find a way to scan all the .h file and get the content of the .h files,let alone exchange the annotation. I really appreciate your help,thank you.

mahal tertin
  • 3,239
  • 24
  • 41

2 Answers2

0

To read, scan and write to text-files, it's easiest to use NSMutableData and dataWithContentsOfURL:

Then parse with NSString and the like, see Converting NSString to NSData and vice versa

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/#//apple_ref/occ/clm/NSData/dataWithContentsOfURL:

Community
  • 1
  • 1
mahal tertin
  • 3,239
  • 24
  • 41
0

Finally,I write the codes like this:

//1、scan all the .h file.

-(NSArray *)filesWithSuffix:(NSString *)suffix atFilePath:(NSString *)path{
NSFileManager * fileManager = [NSFileManager defaultManager];
NSError * error;
NSArray * array = [fileManager subpathsOfDirectoryAtPath:path error:&error];

NSMutableArray *mutableArray = [NSMutableArray array];
for (NSString *ele in array){

    if ([[ele substringFromIndex:(ele.length - suffix.length)] isEqualToString:suffix]){
        [mutableArray addObject:ele];
    }
}
return [mutableArray copy];}

and call the method:

NSArray *filePaths = [self filesWithSuffix:@".h" atFilePath:path];