diff --git a/Foundation/NSBundle.swift b/Foundation/NSBundle.swift index 9a2adb5843..58e89ac1cc 100644 --- a/Foundation/NSBundle.swift +++ b/Foundation/NSBundle.swift @@ -205,7 +205,7 @@ public class NSBundle : NSObject { } public func pathForResource(name: String?, ofType ext: String?, inDirectory subpath: String?) -> String? { - return self.URLForResource(name, withExtension: ext, subdirectory: nil)?.path + return self.URLForResource(name, withExtension: ext, subdirectory: subpath)?.path } public func pathForResource(name: String?, ofType ext: String?, inDirectory subpath: String?, forLocalization localizationName: String?) -> String? { diff --git a/TestFoundation/TestNSBundle.swift b/TestFoundation/TestNSBundle.swift index 63eb0a5f5e..67ae3affc3 100644 --- a/TestFoundation/TestNSBundle.swift +++ b/TestFoundation/TestNSBundle.swift @@ -98,6 +98,9 @@ class TestNSBundle : XCTestCase { private let _bundleName = "MyBundle.bundle" private let _bundleResourceNames = ["hello.world", "goodbye.world", "swift.org"] + private let _subDirectory = "Sources" + private let _main = "main" + private let _type = "swift" private func _setupPlayground() -> String? { // Make sure the directory is uniquely named @@ -114,6 +117,10 @@ class TestNSBundle : XCTestCase { for n in _bundleResourceNames { NSFileManager.defaultManager().createFileAtPath(bundlePath + "/" + n, contents: nil, attributes: nil) } + // Add a resource into a subdirectory + let subDirPath = bundlePath + "/" + _subDirectory + try NSFileManager.defaultManager().createDirectoryAtPath(subDirPath, withIntermediateDirectories: false, attributes: nil) + NSFileManager.defaultManager().createFileAtPath(subDirPath + "/" + _main + "." + _type, contents: nil, attributes: nil) } catch _ { return nil } @@ -140,6 +147,9 @@ class TestNSBundle : XCTestCase { XCTAssertNotNil(worldResources) XCTAssertEqual(worldResources?.count, 2) + let path = bundle?.pathForResource(_main, ofType: _type, inDirectory: _subDirectory) + XCTAssertNotNil(path) + _cleanupPlayground(playground) } }