Skip to content

Commit 11212e0

Browse files
committed
Add ResourceName
1 parent 235f305 commit 11212e0

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// ResourceName.swift
3+
// SwiftAndroid
4+
//
5+
// Created by Alsey Coleman Miller on 6/10/25.
6+
//
7+
8+
import JavaKit
9+
10+
/// Android Resource ID
11+
///
12+
/// Return the full name for a given resource identifier. This name is a single string of the form "package:type/entry".
13+
public struct ResourceName: Equatable, Hashable, Codable, Sendable {
14+
15+
public let name: String
16+
17+
public let type: String
18+
19+
public let package: String
20+
21+
public init(name: String, type: String, package: String) {
22+
self.name = name
23+
self.type = type
24+
self.package = package
25+
}
26+
}
27+
28+
// MARK: - Extensions
29+
30+
public extension ResourceID {
31+
32+
init?(name: ResourceName, in resources: Resources) {
33+
self.init(name: name.name, type: name.type, package: name.package, in: resources)
34+
}
35+
}
36+
37+
// MARK: - RawRepresentable
38+
39+
extension ResourceName: RawRepresentable {
40+
41+
public init?(rawValue: String) {
42+
// TODO: Parse resource string
43+
fatalError("Not implemented")
44+
}
45+
46+
public var rawValue: String {
47+
self.package + ":" + self.type + "/" + self.name
48+
}
49+
}
50+
51+
// MARK: - CustomStringConvertible
52+
53+
extension ResourceName: CustomStringConvertible {
54+
55+
public var description: String {
56+
rawValue
57+
}
58+
}

0 commit comments

Comments
 (0)