Search code examples
objective-cswiftmacosnstask

NSTask / Process deprecated methods and properties


In the most recent Apple documentation both NSTask and Process have several deprecated methods and properties, although there's nothing marked with an API Availability Macro.

Instance Properties

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

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

Instance Methods

- (void)launch;

func launch()

Type Methods

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

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

There seemingly are no replacements available, so what gives?


Solution

  • There seemingly are no replacements available

    There are, the API is now URL related

    Instance Properties

    @property(copy) NSURL *executableURL;
    @property(copy) NSURL *currentDirectoryURL;
    
    var executableURL: URL? { get set }
    var currentDirectoryURL: URL? { get set }
    

    Instance Methods

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

    Type Methods

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