자바 (안드로이드)에서 온 것처럼 objetive-c를 처음 접했고 약간의 AppleScript를 사용했습니다.NSTask 또는 AScript?
그래서 내 애플은 자식 커밋을하고있다. 하지만 터미널에서 사용자가보고 싶어하는 출력이 있음을 알고 있습니다. 그래서 장면 뒤에서 NSTask를 계속 사용해야합니까? 아니면 AppleScript를 사용하고 사용자가 터미널에서 계속 진행하도록해야합니까? 주로 내 push.m은 다음과 같습니다.
#import "Push.h"
@implementation Push
@synthesize test;
@synthesize dirPath;
-(IBAction)chooseFolder:(id)sender{
dirPath = [self get];
NSArray *array = [dirPath componentsSeparatedByString:@"/"];
NSString *pub = [array lastObject];
[projectName setStringValue:pub];
BOOL fileyn = [self check:dirPath];
if(fileyn) {
} else {
}
}
-(IBAction)pushAction:(id)sender {
[self push];
[self push];
}
-(void)push{
if(dirPath == nil || dirPath == @"") {
[self chooseFolder:nil];
}
NSString *commitText = [commitMessage stringValue];
[commitMessage setStringValue:@""];
commitText = [NSString stringWithFormat:@"%@",commitText];
if (i == 1) {
} else {
[self runScript:dirPath:@"add" :@"*" :nil];
[self runScript:dirPath:@"commit" :@"-m" :commitText];
[self runScript:dirPath:@"push" :@"origin" :@"HEAD"];
}
}
-(void) runScript:(NSString *) path:(NSString*)cmd1:(NSString *) cmd2:(NSString *) cmd3{
NSTask *aTask = [[NSTask alloc] init];
NSPipe *pipe;
pipe = [NSPipe pipe];
[aTask setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSArray* args = [NSArray arrayWithObjects:cmd1,cmd2,cmd3, nil];
[aTask setArguments:args];
[aTask setCurrentDirectoryPath:path];
[aTask setLaunchPath:@"/usr/local/git/bin/git"];
[aTask setArguments:args];
[aTask launch];
[finished setStringValue:@"finished"];
}
-(IBAction)back:(id)sender{
test = [[NSWindowController alloc] initWithWindowNibName:@"POP"];
[test showWindow:self];
[window close];
}
-(BOOL)check:(NSString *) pow{
BOOL isFile = [[NSFileManager defaultManager] fileExistsAtPath:pow isDirectory:NO];
return isFile;
}
-(NSString *)get {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
if ([panel runModal] != NSFileHandlingPanelOKButton) return nil;
return [[panel directoryURL] path];
}
@end
그럼 어떻게해야합니까? 개선 할 것이 있다면? 미리 감사드립니다!
제쳐두고'=='은 objective-c에서 문자열을 비교하는 방법이 아닙니다. – vcsjones
또한'git'을'/ usr/local/git/bin /'으로 하드 코딩하는 것이 좋습니다. 제기랄? 나는 기본적으로'/ usr/bin/git'에 살고 있으며, 자신의 버전을 설치하는 사람들은/usr/local/bin에있다./git' ... –