NSTask / Process 弃用的方法和属性

NSTask / Process deprecated methods and properties

在最新的 Apple 文档中 NSTask and Process have several deprecated methods and properties, although there's nothing marked with an API Availability Macro

实例属性

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

var launchPath: String? { get set }
var currentDirectoryPath: String { get set }

实例方法

- (void)launch;

func launch()

类型方法

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

class func launchedProcess(launchPath path: String, 
                 arguments: [String]) -> Process

似乎没有可用的替代品,那又如何呢?

There seemingly are no replacements available

有,API现在URL相关

实例属性

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

var executableURL: URL? { get set }
var currentDirectoryURL: URL? { get set }

实例方法

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

func run() throws

类型方法

+ (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