Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 825c0df

Browse files
committed
Introduce R.file.someJson.url() and .path()
These convienence methods feel right and I think they should help when we look into R.swift issue #150.
1 parent d9d1148 commit 825c0df

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Library/Core/FileResource.swift

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ public protocol FileResourceType {
2020
var pathExtension: String { get }
2121
}
2222

23+
public extension FileResourceType {
24+
/**
25+
Returns the full pathname for this resource.
26+
27+
- returns: The full pathname for this resource or nil if the file could not be located.
28+
*/
29+
func path() -> String? {
30+
return bundle?.pathForResource(self)
31+
}
32+
33+
/**
34+
Returns the file URL for this resource.
35+
36+
- returns: The file URL for this resource or nil if the file could not be located.
37+
*/
38+
func url() -> NSURL? {
39+
return bundle?.urlForResource(self)
40+
}
41+
}
42+
2343
public struct FileResource: FileResourceType {
2444
/// Bundle this file is in or nil for main bundle
2545
public let bundle: NSBundle?

0 commit comments

Comments
 (0)