objective-c - NSTask/Process 弃用的方法和属性

标签 objective-c swift macos nstask

在最新的 Apple 文档中, NSTask Process 有几个已弃用 的方法和属性,尽管没有任何标记有 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

关于objective-c - NSTask/Process 弃用的方法和属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47315066/

相关文章:

macos - 在 Mac 上安装 R - 使用 "C"的警告消息 : Setting LC_CTYPE failed,

linux - 在 ansible 中从远程位置安装

ios - 应用程序本地化显示键而不是 iOS 中的值

swift - 当缺少值时,Codable 结构中使用的可选属性包装器失败

ios - 为什么我的 NSFetchedResultsController 加载所有行?

ios - 解包核心数据中的可选值时发现 nil

ios - 如何在 RxSwift 中配置 bool 流

python - 为什么 Python easy_install 不能在我的 Mac 上运行?

ios - uiscrollview 中的 UIViewControllers 调用 viewdidappear

ios - NSMutableData 到 NSString