@@ -27,52 +27,43 @@ dependencies: [
2727
2828## Usage
2929
30- ### JSON Files
30+ SwiftEmbed provides two ways to load resources:
31+ - ** Property wrappers** (` @Embedded.json ` / ` @Embedded.yaml ` ) - for class/struct properties
32+ - ** Direct loading** (` Embedded.getJSON ` / ` Embedded.getYAML ` ) - for immediate use
33+
34+ ### Property Wrappers
3135
3236``` swift
3337import SwiftEmbed
3438
39+ struct Config : Decodable {
40+ let apiURL: String
41+ let timeout: Int
42+ let features: [String ]
43+ }
44+
3545struct User : Decodable {
3646 let name: String
3747 let email: String
3848}
3949
40- struct MyClass {
50+ struct MyApp {
4151 @Embedded .json (" Resources/users.json" )
4252 var users: [User]
4353
44- func printUsers () {
45- for user in users {
46- print (" \( user.name ) : \( user.email ) " )
47- }
48- }
49- }
50- ```
51-
52- ### YAML Files
53-
54- ``` swift
55- import SwiftEmbed
56-
57- struct Config : Decodable {
58- let apiURL: String
59- let timeout: Int
60- }
61-
62- struct Settings {
6354 @Embedded .yaml (" Config/settings.yaml" )
6455 var config: Config
6556
66- func configure () {
67- print (" API URL : \( config.apiURL ) " )
68- print (" Timeout : \( config. timeout ) s " )
57+ func printInfo () {
58+ print (" API: \( config.apiURL ) " )
59+ print (" Users : \( users. count ) " )
6960 }
7061}
7162```
7263
7364### In Tests
7465
75- Perfect for loading test data:
66+ Perfect for loading test data with parametrized tests :
7667
7768``` swift
7869import Testing
@@ -85,16 +76,30 @@ struct APITests {
8576 let expected: String
8677 }
8778
88- @Embedded .json (" TestData/url_tests.json" )
89- var testCases: [TestCase]
90-
91- @Test (" URL Validation" , arguments: testCases)
79+ @Test (" URL Validation" , arguments: Embedded.getJSON (" TestData/url_tests.json" , as : [TestCase].self ))
9280 func testURLs (testCase : TestCase) {
9381 // Test implementation
9482 }
9583}
9684```
9785
86+ ### Direct Loading
87+
88+ You can also load resources directly without property wrappers:
89+
90+ ``` swift
91+ import SwiftEmbed
92+
93+ // Load and decode JSON
94+ let users = Embedded.getJSON (" users.json" , as : [User].self )
95+
96+ // Load and decode YAML
97+ let config = Embedded.getYAML (" config.yaml" , as : Config.self )
98+
99+ // Specify bundle explicitly
100+ let data = Embedded.getJSON (" data.json" , bundle : Bundle.module , as : MyData.self )
101+ ```
102+
98103## File Organization
99104
100105Place your resource files in your target:
0 commit comments