2. What is NSTask for?
NSTask Class 사용 목적
•
다른 프로그램을 서브프로세스
로 띄우고 싶을 때
•
다른 프로그램을 모니터하고 싶
을때
•
Unix함수인 fork()와 exec()를 사
용하기 쉽게 래핑한 것
3. How to use NSTask?
$ zipinfo -1 test.zip | {stdout}
NSTask
NSPipe
NSData
프로세스는 표준 입력(stdin)으로 데이터를 읽어오고 표준
출력(stdout)과 표준 에러(stderr)로 데이터를 작성함
외부 프로세스로부터 데이터를 파이프NSPipe 클래스를 통
해 가져옴
4.
5. 구현 순서
1. /usr/bin/zipinfo라는 외부 프로세스를 이용하는 애플리케이션
을 작성한다.
2. 외부 프로세스에 몇 가지 인수를 보내고, 프로세스의 표준 출력
에서 결과를 읽어온다.
3. Xcode에 ZIPspector 라는 이름으로 새로운 Cocoa Application
프로젝트를 생성한다.
4. 파일 연동을 위해 target의 정보에 UTI 값을 넣고 Viewer 역할을
부여한다.
5. readFromData 대신 readFromURL에 NSTask를 정의한다.
6. NSPipe을 통해 NSTask의 stdout을 읽어오고 이를 tableView에
뿌린다.
9. 문제
tar와 tgz 도 동작할 수 있도록 UTI identifier 추가
1. TAR UTI : public.tar-archive
2. TGZ UTI : org.gnu.gnu-zip-tar-archive
3. TAR.Z UTI : LZW format - http://
stackoverflow.com/questions/13216935/tar-z-fileformat-structure-header
10. Thanks
Uniform Type Identifiers Reference
https://developer.apple.com/library/mac/documentation/Miscellaneous/
Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html