Skip to content

Commit 49bcd5c

Browse files
committed
change FileManager.default() class function to static let
to match Darwin version as of Xcode 8
1 parent 7c28dca commit 49bcd5c

13 files changed

+59
-62
lines changed

Foundation/NSData.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ extension NSData {
408408
if fd == -1 {
409409
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
410410
}
411-
let pathResult = FileManager.default().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
411+
let pathResult = FileManager.default.string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
412412
return (fd, pathResult)
413413
}
414414

@@ -472,7 +472,7 @@ extension NSData {
472472
} catch let err {
473473
if let auxFilePath = auxFilePath {
474474
do {
475-
try FileManager.default().removeItem(atPath: auxFilePath)
475+
try FileManager.default.removeItem(atPath: auxFilePath)
476476
} catch _ {}
477477
}
478478
throw err
@@ -482,7 +482,7 @@ extension NSData {
482482
if let auxFilePath = auxFilePath {
483483
if rename(auxFilePath, path) != 0 {
484484
do {
485-
try FileManager.default().removeItem(atPath: auxFilePath)
485+
try FileManager.default.removeItem(atPath: auxFilePath)
486486
} catch _ {}
487487
throw _NSErrorWithErrno(errno, reading: false, path: path)
488488
}

Foundation/NSFileManager.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ open class FileManager: NSObject {
7070

7171
/* Returns the default singleton instance.
7272
*/
73-
internal static let defaultInstance = FileManager()
74-
open class func `default`() -> FileManager {
75-
return defaultInstance
76-
}
73+
public static let default = FileManager()
7774

7875
/* Returns an NSArray of NSURLs locating the mounted volumes available on the computer. The property keys that can be requested are available in NSURL.
7976
*/
@@ -461,7 +458,7 @@ open class FileManager: NSObject {
461458
return
462459
} else if errno == ENOTEMPTY {
463460

464-
let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
461+
let fsRep = FileManager.default.fileSystemRepresentation(withPath: path)
465462
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
466463
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
467464
ps.advanced(by: 1).initialize(to: nil)
@@ -733,7 +730,7 @@ open class FileManager: NSObject {
733730
return nil
734731
}
735732

736-
guard let destination = try? FileManager.default().destinationOfSymbolicLink(atPath: path) else {
733+
guard let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path) else {
737734
return nil
738735
}
739736

@@ -874,7 +871,7 @@ extension FileManager {
874871
init?(path: String) {
875872
let url = URL(fileURLWithPath: path)
876873
self.baseURL = url
877-
guard let ie = FileManager.default().enumerator(at: url, includingPropertiesForKeys: nil, options: [], errorHandler: nil) else {
874+
guard let ie = FileManager.default.enumerator(at: url, includingPropertiesForKeys: nil, options: [], errorHandler: nil) else {
878875
return nil
879876
}
880877
self.innerEnumerator = ie
@@ -906,8 +903,8 @@ extension FileManager {
906903
_errorHandler = errorHandler
907904

908905
if let path = _url.path {
909-
if FileManager.default().fileExists(atPath: path) {
910-
let fsRep = FileManager.default().fileSystemRepresentation(withPath: path)
906+
if FileManager.default.fileExists(atPath: path) {
907+
let fsRep = FileManager.default.fileSystemRepresentation(withPath: path)
911908
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
912909
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
913910
ps.advanced(by: 1).initialize(to: nil)

Foundation/NSKeyedArchiver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ open class NSKeyedArchiver : NSCoder {
148148
if finishedEncoding {
149149
try _NSCleanupTemporaryFile(auxFilePath, path)
150150
} else {
151-
try FileManager.default().removeItem(atPath: auxFilePath)
151+
try FileManager.default.removeItem(atPath: auxFilePath)
152152
}
153153
} catch _ {
154154
}

Foundation/NSPathUtilities.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ internal extension String {
146146
}
147147

148148
let temp = _stringByRemovingPrefix(prefix)
149-
if FileManager.default().fileExists(atPath: temp) {
149+
if FileManager.default.fileExists(atPath: temp) {
150150
return temp
151151
}
152152

@@ -347,7 +347,7 @@ public extension NSString {
347347

348348
default:
349349
resolvedPath = resolvedPath.bridge().stringByAppendingPathComponent(component)
350-
if let destination = FileManager.default()._tryToResolveTrailingSymlinkInPath(resolvedPath) {
350+
if let destination = FileManager.default._tryToResolveTrailingSymlinkInPath(resolvedPath) {
351351
resolvedPath = destination
352352
}
353353
}
@@ -427,7 +427,7 @@ public extension NSString {
427427
}
428428

429429
var isDirectory = false
430-
let exists = FileManager.default().fileExists(atPath: path, isDirectory: &isDirectory)
430+
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
431431
return exists && isDirectory
432432
}
433433

@@ -436,7 +436,7 @@ public extension NSString {
436436
internal func _getNamesAtURL(_ filePathURL: URL, prependWith: String, namePredicate: _FileNamePredicate, typePredicate: _FileNamePredicate) -> [String] {
437437
var result: [String] = []
438438

439-
if let enumerator = FileManager.default().enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
439+
if let enumerator = FileManager.default.enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
440440
for item in enumerator.lazy.map({ $0 as! URL }) {
441441
let itemName = item.lastPathComponent
442442

@@ -618,14 +618,14 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
618618
if fd == -1 {
619619
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
620620
}
621-
let pathResult = FileManager.default().string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
621+
let pathResult = FileManager.default.string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
622622
return (fd, pathResult)
623623
}
624624

625625
internal func _NSCleanupTemporaryFile(_ auxFilePath: String, _ filePath: String) throws {
626626
if rename(auxFilePath, filePath) != 0 {
627627
do {
628-
try FileManager.default().removeItem(atPath: auxFilePath)
628+
try FileManager.default.removeItem(atPath: auxFilePath)
629629
} catch _ {
630630
}
631631
throw _NSErrorWithErrno(errno, reading: false, path: filePath)

Foundation/NSURL.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ open class NSURL: NSObject, NSSecureCoding, NSCopying {
267267
} else {
268268
absolutePath = path
269269
}
270-
let _ = FileManager.default().fileExists(atPath: absolutePath, isDirectory: &isDir)
270+
let _ = FileManager.default.fileExists(atPath: absolutePath, isDirectory: &isDir)
271271
} catch {
272272
// ignored
273273
}
@@ -287,7 +287,7 @@ open class NSURL: NSObject, NSSecureCoding, NSCopying {
287287
if thePath.hasSuffix("/") {
288288
isDir = true
289289
} else {
290-
let _ = FileManager.default().fileExists(atPath: path, isDirectory: &isDir)
290+
let _ = FileManager.default.fileExists(atPath: path, isDirectory: &isDir)
291291
}
292292

293293
self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeTo: nil)
@@ -697,7 +697,7 @@ extension NSURL {
697697
if let urlWithoutDirectory = result,
698698
let path = urlWithoutDirectory.path {
699699
var isDir : Bool = false
700-
if FileManager.default().fileExists(atPath: path, isDirectory: &isDir) && isDir {
700+
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) && isDir {
701701
result = self.appendingPathComponent(pathComponent, isDirectory: true)
702702
}
703703
}
@@ -747,7 +747,7 @@ extension NSURL {
747747
if selfPath.hasPrefix("/") {
748748
absolutePath = selfPath
749749
} else {
750-
let workingDir = FileManager.default().currentDirectoryPath
750+
let workingDir = FileManager.default.currentDirectoryPath
751751
absolutePath = workingDir.bridge().stringByAppendingPathComponent(selfPath)
752752
}
753753

@@ -769,15 +769,15 @@ extension NSURL {
769769

770770
default:
771771
resolvedPath = resolvedPath.bridge().stringByAppendingPathComponent(component)
772-
if let destination = FileManager.default()._tryToResolveTrailingSymlinkInPath(resolvedPath) {
772+
if let destination = FileManager.default._tryToResolveTrailingSymlinkInPath(resolvedPath) {
773773
resolvedPath = destination
774774
}
775775
}
776776
}
777777

778778
// It might be a responsibility of NSURL(fileURLWithPath:). Check it.
779779
var isExistingDirectory = false
780-
let _ = FileManager.default().fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)
780+
let _ = FileManager.default.fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)
781781

782782
if excludeSystemDirs {
783783
resolvedPath = resolvedPath._tryToRemovePathPrefix("/private") ?? resolvedPath

TestFoundation/TestNSBundle.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TestNSBundle : XCTestCase {
6868
let testPlist = bundle.urlForResource("Test", withExtension: "plist")
6969
XCTAssertNotNil(testPlist)
7070
XCTAssertEqual("Test.plist", testPlist!.lastPathComponent)
71-
XCTAssert(FileManager.default().fileExists(atPath: testPlist!.path!))
71+
XCTAssert(FileManager.default.fileExists(atPath: testPlist!.path!))
7272

7373
// aliases, paths
7474
XCTAssertEqual(testPlist!.path, bundle.urlForResource("Test", withExtension: "plist", subdirectory: nil)!.path)
@@ -111,20 +111,20 @@ class TestNSBundle : XCTestCase {
111111
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
112112

113113
do {
114-
try FileManager.default().createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
114+
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
115115

116116
// Make a flat bundle in the playground
117117
let bundlePath = tempDir + _bundleName
118-
try FileManager.default().createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)
118+
try FileManager.default.createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)
119119

120120
// Put some resources in the bundle
121121
for n in _bundleResourceNames {
122-
let _ = FileManager.default().createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
122+
let _ = FileManager.default.createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
123123
}
124124
// Add a resource into a subdirectory
125125
let subDirPath = bundlePath + "/" + _subDirectory
126-
try FileManager.default().createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
127-
let _ = FileManager.default().createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
126+
try FileManager.default.createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
127+
let _ = FileManager.default.createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
128128
} catch _ {
129129
return nil
130130
}
@@ -135,7 +135,7 @@ class TestNSBundle : XCTestCase {
135135

136136
private func _cleanupPlayground(_ location: String) {
137137
do {
138-
try FileManager.default().removeItem(atPath: location)
138+
try FileManager.default.removeItem(atPath: location)
139139
} catch _ {
140140
// Oh well
141141
}

TestFoundation/TestNSData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TestNSData: XCTestCase {
4949
let savePath = URL(fileURLWithPath: "/var/tmp/Test.plist")
5050
do {
5151
try saveData.write(to: savePath, options: .dataWritingAtomic)
52-
let fileManager = FileManager.default()
52+
let fileManager = FileManager.default
5353
XCTAssertTrue(fileManager.fileExists(atPath: savePath.path!))
5454
try! fileManager.removeItem(atPath: savePath.path!)
5555
} catch _ {

TestFoundation/TestNSFileManager.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TestNSFileManager : XCTestCase {
3737
}
3838

3939
func test_createDirectory() {
40-
let fm = FileManager.default()
40+
let fm = FileManager.default
4141
let path = "/tmp/testdir\(NSUUID().uuidString)"
4242

4343
ignoreError { try fm.removeItem(atPath: path) }
@@ -62,7 +62,7 @@ class TestNSFileManager : XCTestCase {
6262
}
6363

6464
func test_createFile() {
65-
let fm = FileManager.default()
65+
let fm = FileManager.default
6666
let path = "/tmp/testfile\(NSUUID().uuidString)"
6767

6868
ignoreError { try fm.removeItem(atPath: path) }
@@ -82,7 +82,7 @@ class TestNSFileManager : XCTestCase {
8282
}
8383

8484
func test_moveFile() {
85-
let fm = FileManager.default()
85+
let fm = FileManager.default
8686
let path = "/tmp/testfile\(NSUUID().uuidString)"
8787
let path2 = "/tmp/testfile2\(NSUUID().uuidString)"
8888

@@ -105,15 +105,15 @@ class TestNSFileManager : XCTestCase {
105105

106106
func test_fileSystemRepresentation() {
107107
let str = ""
108-
let result = FileManager.default().fileSystemRepresentation(withPath: str)
108+
let result = FileManager.default.fileSystemRepresentation(withPath: str)
109109
XCTAssertNotNil(result)
110110
XCTAssertEqual(UInt8(bitPattern: result[0]), 0xE2)
111111
XCTAssertEqual(UInt8(bitPattern: result[1]), 0x98)
112112
XCTAssertEqual(UInt8(bitPattern: result[2]), 0x83)
113113
}
114114

115115
func test_fileAttributes() {
116-
let fm = FileManager.default()
116+
let fm = FileManager.default
117117
let path = "/tmp/test_fileAttributes\(NSUUID().uuidString)"
118118

119119
ignoreError { try fm.removeItem(atPath: path) }
@@ -162,7 +162,7 @@ class TestNSFileManager : XCTestCase {
162162

163163
func test_setFileAttributes() {
164164
let path = "/tmp/test_setFileAttributes\(NSUUID().uuidString)"
165-
let fm = FileManager.default()
165+
let fm = FileManager.default
166166

167167
ignoreError { try fm.removeItem(atPath: path) }
168168
XCTAssertTrue(fm.createFile(atPath: path, contents: Data(), attributes: nil))
@@ -187,7 +187,7 @@ class TestNSFileManager : XCTestCase {
187187
}
188188

189189
func test_pathEnumerator() {
190-
let fm = FileManager.default()
190+
let fm = FileManager.default
191191
let testDirName = "testdir\(NSUUID().uuidString)"
192192
let basePath = "/tmp/\(testDirName)"
193193
let itemPath = "/tmp/\(testDirName)/item"
@@ -207,7 +207,7 @@ class TestNSFileManager : XCTestCase {
207207
XCTFail()
208208
}
209209

210-
if let e = FileManager.default().enumerator(atPath: basePath) {
210+
if let e = FileManager.default.enumerator(atPath: basePath) {
211211
let foundItems = NSMutableSet()
212212
while let item = e.nextObject() as? NSString {
213213
foundItems.add(item)
@@ -220,7 +220,7 @@ class TestNSFileManager : XCTestCase {
220220
}
221221

222222
func test_directoryEnumerator() {
223-
let fm = FileManager.default()
223+
let fm = FileManager.default
224224
let testDirName = "testdir\(NSUUID().uuidString)"
225225
let path = "/tmp/\(testDirName)"
226226
let itemPath = "/tmp/\(testDirName)/item"
@@ -234,7 +234,7 @@ class TestNSFileManager : XCTestCase {
234234
XCTFail()
235235
}
236236

237-
if let e = FileManager.default().enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
237+
if let e = FileManager.default.enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
238238
var foundItems = [String:Int]()
239239
while let item = e.nextObject() as? NSURL {
240240
if let p = item.path {
@@ -255,7 +255,7 @@ class TestNSFileManager : XCTestCase {
255255
XCTFail()
256256
}
257257

258-
if let e = FileManager.default().enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
258+
if let e = FileManager.default.enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
259259
var foundItems = [String:Int]()
260260
while let item = e.nextObject() as? NSURL {
261261
if let p = item.path {
@@ -269,7 +269,7 @@ class TestNSFileManager : XCTestCase {
269269
XCTFail()
270270
}
271271

272-
if let e = FileManager.default().enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants], errorHandler: nil) {
272+
if let e = FileManager.default.enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants], errorHandler: nil) {
273273
var foundItems = [String:Int]()
274274
while let item = e.nextObject() as? NSURL {
275275
if let p = item.path {
@@ -282,7 +282,7 @@ class TestNSFileManager : XCTestCase {
282282
XCTFail()
283283
}
284284

285-
if let e = FileManager.default().enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
285+
if let e = FileManager.default.enumerator(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: [], errorHandler: nil) {
286286
var foundItems = [String:Int]()
287287
while let item = e.nextObject() as? NSURL {
288288
if let p = item.path {
@@ -300,15 +300,15 @@ class TestNSFileManager : XCTestCase {
300300
didGetError = true
301301
return true
302302
}
303-
if let e = FileManager.default().enumerator(at: URL(fileURLWithPath: "/nonexistant-path"), includingPropertiesForKeys: nil, options: [], errorHandler: handler) {
303+
if let e = FileManager.default.enumerator(at: URL(fileURLWithPath: "/nonexistant-path"), includingPropertiesForKeys: nil, options: [], errorHandler: handler) {
304304
XCTAssertNil(e.nextObject())
305305
} else {
306306
XCTFail()
307307
}
308308
XCTAssertTrue(didGetError)
309309

310310
do {
311-
let contents = try FileManager.default().contentsOfDirectory(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: []).map {
311+
let contents = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: path), includingPropertiesForKeys: nil, options: []).map {
312312
return $0.path!
313313
}
314314
XCTAssertEqual(contents.count, 2)
@@ -326,7 +326,7 @@ class TestNSFileManager : XCTestCase {
326326
}
327327

328328
func test_contentsOfDirectoryAtPath() {
329-
let fm = FileManager.default()
329+
let fm = FileManager.default
330330
let testDirName = "testdir\(NSUUID().uuidString)"
331331
let path = "/tmp/\(testDirName)"
332332
let itemPath1 = "/tmp/\(testDirName)/item"
@@ -370,7 +370,7 @@ class TestNSFileManager : XCTestCase {
370370
}
371371

372372
func test_subpathsOfDirectoryAtPath() {
373-
let fm = FileManager.default()
373+
let fm = FileManager.default
374374
let path = "/tmp/testdir"
375375
let path2 = "/tmp/testdir/sub"
376376
let itemPath1 = "/tmp/testdir/item"

0 commit comments

Comments
 (0)