Skip to content

Commit ec74eea

Browse files
committed
Add ResourceID convenience initializer
1 parent 8e8fc22 commit ec74eea

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/AndroidContent/ResourceID.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public extension ResourceID {
3232
self.init(rawValue: rawValue)
3333
}
3434

35+
/// Return a resource identifier for the given resource name.
36+
init?(name: String, type: String, in context: Context) {
37+
let packageName = context.getPackageName()
38+
guard let resources = context.getResources() else {
39+
return nil
40+
}
41+
self.init(name: name, type: type, package: packageName, in: resources)
42+
}
43+
3544
/// Return the full name for a given resource identifier. This name is a single string of the form "package:type/entry".
3645
func name(in resources: Resources) throws -> String {
3746
try resources.getResourceName(rawValue)

0 commit comments

Comments
 (0)