J'essaie de comprendre comment passer une variable (dans mon cas hostname) à une fonction que j'ai créée à partir d'un élément de menu inséré par programmation.Cocoa Xcode - comment passer une variable à une fonction
#function
-(void)goToTerminal:(NSString *)hostname {
NSString *s = [NSString stringWithFormat:@"tell application \"Terminal\" to do script \"ssh [email protected]%@\"", hostname];
NSAppleScript *as = [[NSAppleScript alloc] initWithSource: s];
[as executeAndReturnError:nil];
}
# adding menu item in another function
[NSString *hostname = [NSString stringWithString:@"some.host"]];
NSMenuItem *subhostline = [[[NSMenuItem alloc] initWithTitle:sshtohost action:@selector(goToTerminal:) keyEquivalent:@""]autorelease];
[subhostline setTarget:self];
Je ne sais pas pourquoi quelqu'un a essayé de baisser la question - c'est une très bonne question! – bbum
Juste une note, il y a une fuite de mémoire dans
goToTerminal:
, la variableas
n'est jamais libérée (auto). –