Pregunta

I'm trying to make a plugin, and the idea is that after you write something like

-(void)thisMethodIsSomethingIWantToBeExposed

Then I can press a keycombo like alt+c and then it'll write what is one the current line in the .h file so I don't have to copy paste it over myself.

Anyone have any idea on how to get the path of the file I'm currently writing in? Then I can just change the m to an h, and then I'll just have to figure out how to write to the h file, but that's another thing.

¿Fue útil?

Solución

I found a solution, but I think it might be a bit hacky.

In my xcode plugin i put this in my init

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationListener:) name:nil object:nil];

And I made a method called

-(void)notificationListener:(NSNotification *)notification{
if (![notification.name isKindOfClass:[NSString class]]) {

    if ([[notification name] isEqualToString:@"IDESourceCodeDocumentDidUpdateSourceModelNotification"] ) {

        NSString *path =  [ NSString stringWithFormat :@"%@",notification.object ];
        path = [path substringFromIndex:49];


    }

You'll get ALOT of notifications, and it took me a while to find one with information on the path, but this one has it.

Same method with

NSLog(@"Not recv: %@", notification.name); 

will write out all the names of all the Notifications.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top