Skip to content

SR-794 pass supplied subpath through to URLForResource rather than nil #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/NSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
10 changes: 10 additions & 0 deletions TestFoundation/TestNSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}
}