Skip to content

Commit 704ce5f

Browse files
mbvreddyparkera
authored andcommitted
Changing NSFileManager API names to match Darwin version (#317)
* Change of NSFileManager API's name * Change variable names to lower camelcase
1 parent 3857357 commit 704ce5f

File tree

10 files changed

+151
-151
lines changed

10 files changed

+151
-151
lines changed

Foundation/NSData.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ extension NSData {
402402
if fd == -1 {
403403
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
404404
}
405-
let pathResult = NSFileManager.defaultManager().stringWithFileSystemRepresentation(buf, length: Int(strlen(buf)))
405+
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
406406
return (fd, pathResult)
407407
}
408408

@@ -462,7 +462,7 @@ extension NSData {
462462
} catch let err {
463463
if let auxFilePath = auxFilePath {
464464
do {
465-
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
465+
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
466466
} catch _ {}
467467
}
468468
throw err
@@ -472,7 +472,7 @@ extension NSData {
472472
if let auxFilePath = auxFilePath {
473473
if rename(auxFilePath, path) != 0 {
474474
do {
475-
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
475+
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
476476
} catch _ {}
477477
throw _NSErrorWithErrno(errno, reading: false, path: path)
478478
}

Foundation/NSFileManager.swift

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

Foundation/NSKeyedArchiver.swift

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

Foundation/NSPathUtilities.swift

Lines changed: 5 additions & 5 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 NSFileManager.defaultManager().fileExistsAtPath(temp) {
149+
if NSFileManager.defaultManager().fileExists(atPath: temp) {
150150
return temp
151151
}
152152

@@ -446,7 +446,7 @@ public extension NSString {
446446
}
447447

448448
var isDirectory = false
449-
let exists = NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDirectory)
449+
let exists = NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDirectory)
450450
return exists && isDirectory
451451
}
452452

@@ -455,7 +455,7 @@ public extension NSString {
455455
internal func _getNamesAtURL(_ filePathURL: NSURL, prependWith: String, namePredicate: _FileNamePredicate, typePredicate: _FileNamePredicate) -> [String] {
456456
var result: [String] = []
457457

458-
if let enumerator = NSFileManager.defaultManager().enumeratorAtURL(filePathURL, includingPropertiesForKeys: nil, options: .SkipsSubdirectoryDescendants, errorHandler: nil) {
458+
if let enumerator = NSFileManager.defaultManager().enumerator(at: filePathURL, includingPropertiesForKeys: nil, options: .skipsSubdirectoryDescendants, errorHandler: nil) {
459459
for item in enumerator.lazy.map({ $0 as! NSURL }) {
460460
let itemName = item.lastPathComponent
461461

@@ -635,14 +635,14 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
635635
if fd == -1 {
636636
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
637637
}
638-
let pathResult = NSFileManager.defaultManager().stringWithFileSystemRepresentation(buf, length: Int(strlen(buf)))
638+
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation: buf, length: Int(strlen(buf)))
639639
return (fd, pathResult)
640640
}
641641

642642
internal func _NSCleanupTemporaryFile(_ auxFilePath: String, _ filePath: String) throws {
643643
if rename(auxFilePath, filePath) != 0 {
644644
do {
645-
try NSFileManager.defaultManager().removeItemAtPath(auxFilePath)
645+
try NSFileManager.defaultManager().removeItem(atPath: auxFilePath)
646646
} catch _ {
647647
}
648648
throw _NSErrorWithErrno(errno, reading: false, path: filePath)

Foundation/NSURL.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
136136
} else {
137137
absolutePath = path
138138
}
139-
NSFileManager.defaultManager().fileExistsAtPath(absolutePath, isDirectory: &isDir)
139+
NSFileManager.defaultManager().fileExists(atPath: absolutePath, isDirectory: &isDir)
140140
}
141141

142142
self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeToURL: baseURL)
@@ -153,7 +153,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
153153
if thePath.hasSuffix("/") {
154154
isDir = true
155155
} else {
156-
NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDir)
156+
NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDir)
157157
}
158158

159159
self.init(fileURLWithPath: thePath, isDirectory: isDir, relativeToURL: nil)
@@ -482,7 +482,7 @@ extension NSURL {
482482
if !pathComponent.hasSuffix("/") && fileURL {
483483
if let urlWithoutDirectory = result, path = urlWithoutDirectory.path {
484484
var isDir : Bool = false
485-
if NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDir) && isDir {
485+
if NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: &isDir) && isDir {
486486
result = self.URLByAppendingPathComponent(pathComponent, isDirectory: true)
487487
}
488488
}
@@ -561,7 +561,7 @@ extension NSURL {
561561

562562
// It might be a responsibility of NSURL(fileURLWithPath:). Check it.
563563
var isExistingDirectory = false
564-
NSFileManager.defaultManager().fileExistsAtPath(resolvedPath, isDirectory: &isExistingDirectory)
564+
NSFileManager.defaultManager().fileExists(atPath: resolvedPath, isDirectory: &isExistingDirectory)
565565

566566
if excludeSystemDirs {
567567
resolvedPath = resolvedPath._tryToRemovePathPrefix("/private") ?? resolvedPath

TestFoundation/TestNSBundle.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TestNSBundle : XCTestCase {
6464
let testPlist = bundle.URLForResource("Test", withExtension: "plist")
6565
XCTAssertNotNil(testPlist)
6666
XCTAssertEqual("Test.plist", testPlist!.lastPathComponent)
67-
XCTAssert(NSFileManager.defaultManager().fileExistsAtPath(testPlist!.path!))
67+
XCTAssert(NSFileManager.defaultManager().fileExists(atPath: testPlist!.path!))
6868

6969
// aliases, paths
7070
XCTAssertEqual(testPlist!.path, bundle.URLForResource("Test", withExtension: "plist", subdirectory: nil)!.path)
@@ -107,20 +107,20 @@ class TestNSBundle : XCTestCase {
107107
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().UUIDString + "/"
108108

109109
do {
110-
try NSFileManager.defaultManager().createDirectoryAtPath(tempDir, withIntermediateDirectories: false, attributes: nil)
110+
try NSFileManager.defaultManager().createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
111111

112112
// Make a flat bundle in the playground
113113
let bundlePath = tempDir + _bundleName
114-
try NSFileManager.defaultManager().createDirectoryAtPath(bundlePath, withIntermediateDirectories: false, attributes: nil)
114+
try NSFileManager.defaultManager().createDirectory(atPath: bundlePath, withIntermediateDirectories: false, attributes: nil)
115115

116116
// Put some resources in the bundle
117117
for n in _bundleResourceNames {
118-
NSFileManager.defaultManager().createFileAtPath(bundlePath + "/" + n, contents: nil, attributes: nil)
118+
NSFileManager.defaultManager().createFile(atPath: bundlePath + "/" + n, contents: nil, attributes: nil)
119119
}
120120
// Add a resource into a subdirectory
121121
let subDirPath = bundlePath + "/" + _subDirectory
122-
try NSFileManager.defaultManager().createDirectoryAtPath(subDirPath, withIntermediateDirectories: false, attributes: nil)
123-
NSFileManager.defaultManager().createFileAtPath(subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
122+
try NSFileManager.defaultManager().createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
123+
NSFileManager.defaultManager().createFile(atPath: subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil)
124124
} catch _ {
125125
return nil
126126
}
@@ -131,7 +131,7 @@ class TestNSBundle : XCTestCase {
131131

132132
private func _cleanupPlayground(_ location: String) {
133133
do {
134-
try NSFileManager.defaultManager().removeItemAtPath(location)
134+
try NSFileManager.defaultManager().removeItem(atPath: location)
135135
} catch _ {
136136
// Oh well
137137
}

TestFoundation/TestNSData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class TestNSData: XCTestCase {
4949
do {
5050
try saveData!.writeToFile(savePath, options: NSDataWritingOptions.DataWritingAtomic)
5151
let fileManager = NSFileManager.defaultManager()
52-
XCTAssertTrue(fileManager.fileExistsAtPath(savePath))
53-
try! fileManager.removeItemAtPath(savePath)
52+
XCTAssertTrue(fileManager.fileExists(atPath: savePath))
53+
try! fileManager.removeItem(atPath: savePath)
5454
} catch _ {
5555
XCTFail()
5656
}

0 commit comments

Comments
 (0)