Skip to content

Commit f13fb2f

Browse files
committed
Adapt to Swift 3 Foundation API changes
1 parent 85809bc commit f13fb2f

File tree

11 files changed

+176
-5
lines changed

11 files changed

+176
-5
lines changed

Sources/Basic/Lock.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import class Foundation.NSLock
11+
import Foundation
1212

1313
/// A simple lock wrapper.
1414
public struct Lock {
15+
#if os(OSX)
16+
private var _lock = Foundation.Lock()
17+
#else
1518
private var _lock = NSLock()
19+
#endif
1620

1721
/// Create a new lock.
1822
public init() {

Sources/Basic/Shims.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSJSONSerialization = JSONSerialization
20+
21+
#endif

Sources/Commands/Shims.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSProcessInfo = ProcessInfo
20+
21+
#endif

Sources/Get/Shims.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSProcessInfo = ProcessInfo
20+
21+
#endif

Sources/SourceControl/Shims.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSProcessInfo = ProcessInfo
20+
21+
#endif

Sources/Utility/Shims.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSFileHandle = FileHandle
20+
public typealias NSFileManager = FileManager
21+
public typealias NSJSONSerialization = JSONSerialization
22+
public typealias NSProcessInfo = ProcessInfo
23+
24+
public let NSUTF8StringEncoding = String.Encoding.utf8
25+
26+
extension NSJSONSerialization {
27+
public static func jsonObject(with data: NSData, options: JSONSerialization.ReadingOptions) throws -> AnyObject {
28+
return try JSONSerialization.jsonObject(with: data as Data, options: options)
29+
}
30+
}
31+
32+
extension NSFileHandle {
33+
public func write(_ data: NSData) {
34+
write(data as Data)
35+
}
36+
}
37+
38+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSBundle = Bundle
20+
public typealias NSFileHandle = FileHandle
21+
public typealias NSFileManager = FileManager
22+
public typealias NSJSONSerialization = JSONSerialization
23+
24+
#endif

Tests/Basic/LockTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Basic
1515
class LockTests: XCTestCase {
1616
func testBasics() {
1717
// FIXME: Make this a more interesting test once we have concurrency primitives.
18-
var lock = Lock()
18+
var lock = Basic.Lock()
1919
var count = 0
2020
let N = 100
2121
for _ in 0..<N {

Tests/Functional/Shims.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
10+
-------------------------------------------------------------------------
11+
12+
Platform-specific shims for the Swift3 transition.
13+
*/
14+
15+
#if os(OSX)
16+
17+
import Foundation
18+
19+
public typealias NSBundle = Bundle
20+
21+
#endif

Tests/Functional/Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import POSIX
1414
import Utility
1515

1616
#if os(OSX)
17-
import class Foundation.NSBundle
17+
import class Foundation.Bundle
1818
#endif
1919

2020

@@ -107,7 +107,7 @@ enum SwiftPMProduct {
107107
/// Path to currently built binary.
108108
var path: String {
109109
#if os(OSX)
110-
for bundle in NSBundle.allBundles() where bundle.bundlePath.hasSuffix(".xctest") {
110+
for bundle in Bundle.allBundles() where bundle.bundlePath.hasSuffix(".xctest") {
111111
return Path.join(bundle.bundlePath.parentDirectory, exec)
112112
}
113113
fatalError()

0 commit comments

Comments
 (0)