NSTask/Process已弃用的方法和属性

l'L*_*L'l 8 macos objective-c nstask swift

在最近的苹果文档都NSTaskProcess有一些过时的方法和属性,虽然没有什么标有API Availability Macro.

实例属性

@property(copy) NSString *launchPath;
@property(copy) NSString *currentDirectoryPath;

var launchPath: String? { get set }
var currentDirectoryPath: String { get set }
Run Code Online (Sandbox Code Playgroud)

实例方法

- (void)launch;

func launch()
Run Code Online (Sandbox Code Playgroud)

类型方法

+ (NSTask *)launchedTaskWithLaunchPath:(NSString *)path 
                             arguments:(NSArray<NSString *> *)arguments; 

class func launchedProcess(launchPath path: String, 
                 arguments: [String]) -> Process
Run Code Online (Sandbox Code Playgroud)

似乎没有替代品可用,所以给出了什么?

vad*_*ian 12

似乎没有替代品

有,API现在与URL相关

实例属性

@property(copy) NSURL *executableURL;
@property(copy) NSURL *currentDirectoryURL;

var executableURL: URL? { get set }
var currentDirectoryURL: URL? { get set }
Run Code Online (Sandbox Code Playgroud)

实例方法

- (BOOL)launchAndReturnError:(out NSError * _Nullable *)error;

func run() throws
Run Code Online (Sandbox Code Playgroud)

类型方法

+ (NSTask *)launchedTaskWithExecutableURL:(NSURL *)url 
                                arguments:(NSArray<NSString *> *)arguments 
                                    error:(out NSError * _Nullable *)error 
                       terminationHandler:(void (^)(NSTask *))terminationHandler;

class func run(_ url: URL, 
               arguments: [String], 
               terminationHandler: ((Process) -> Void)? = nil) throws -> Process
Run Code Online (Sandbox Code Playgroud)

  • 现在是2019年中期,但XCode文档仍然没有任何概述或讨论记录。而且不推荐使用的函数不会指向要使用的新API。感谢@vadian指出这些。 (3认同)
  • @ user426132在子条款中提到的可可,2017年WWDC的新内容. (2认同)