Skip to content

Commit 97f7b9b

Browse files
AZero13Kyle-Ye
andcommitted
Modernize code to not rely on deprecations and old behavior
Co-Authored-By: Kyle <[email protected]>
1 parent de5f7ed commit 97f7b9b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Darwin/Foundation-swiftoverlay/DataThunks.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static NSInteger _NSWriteToFileDescriptor(int32_t fd, const void *buffer, NSUInt
7575

7676
static NSError *_NSErrorWithFilePath(NSInteger code, id pathOrURL) {
7777
NSString *key = [pathOrURL isKindOfClass:[NSURL self]] ? NSURLErrorKey : NSFilePathErrorKey;
78-
return [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:[NSDictionary dictionaryWithObjectsAndKeys:pathOrURL, key, nil]];
78+
return [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:@{pathOrURL: key}];
7979
}
8080

8181
static NSError *_NSErrorWithFilePathAndErrno(NSInteger posixErrno, id pathOrURL, BOOL reading) {
@@ -106,7 +106,7 @@ static NSInteger _NSWriteToFileDescriptor(int32_t fd, const void *buffer, NSUInt
106106
}
107107

108108
NSString *key = [pathOrURL isKindOfClass:[NSURL self]] ? NSURLErrorKey : NSFilePathErrorKey;
109-
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:pathOrURL, key, [NSError errorWithDomain:NSPOSIXErrorDomain code:posixErrno userInfo:nil], NSUnderlyingErrorKey, nil];
109+
NSDictionary *userInfo = @{pathOrURL : key, [NSError errorWithDomain:NSPOSIXErrorDomain code:posixErrno userInfo:nil] : NSUnderlyingErrorKey};
110110
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:userInfo];
111111
[userInfo release];
112112
return error;

Sources/Foundation/Process.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,11 @@ open class Process: NSObject {
11171117
// convenience; create and launch
11181118
open class func launchedProcess(launchPath path: String, arguments: [String]) -> Process {
11191119
let process = Process()
1120-
process.launchPath = path
1120+
if #available(macOS 10.13, *) {
1121+
process.executableURL = URL(fileURLWithPath:path)
1122+
} else {
1123+
process.launchPath = path
1124+
}
11211125
process.arguments = arguments
11221126
process.launch()
11231127

Tests/Foundation/Tests/TestProcess.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestProcess : XCTestCase {
1212
func test_exit0() throws {
1313
let process = Process()
1414
let executableURL = xdgTestHelperURL()
15-
if #available(OSX 10.13, *) {
15+
if #available(macOS 10.13, *) {
1616
process.executableURL = executableURL
1717
} else {
1818
// Fallback on earlier versions
@@ -971,7 +971,12 @@ internal func runTask(_ arguments: [String], environment: [String: String]? = ni
971971
let process = Process()
972972

973973
var arguments = arguments
974-
process.launchPath = arguments.removeFirst()
974+
if #available(macOS 10.13, *) {
975+
process.executableURL = URL(fileURLWithPath:arguments.removeFirst())
976+
} else {
977+
// Fallback on earlier versions
978+
process.launchPath = arguments.removeFirst()
979+
}
975980
process.arguments = arguments
976981
// Darwin Foundation doesnt allow .environment to be set to nil although the documentation
977982
// says it is an optional. https://developer.apple.com/documentation/foundation/process/1409412-environment

0 commit comments

Comments
 (0)