Includes let you bring in arbitrary HTML from your Includes directory.
For example, the HTML below was imported from Includes/important.html
Include("important.html")
If you want to load arbitrary resources for parsing in your Swift code, you should create a folder called Resources then you have three options.
Each option requires you to add @Environment(\.decode) var decode
as a property for your page.
First, decode.url(forResource:)
tells you the full path to a file in Resources.
Second, decode.data(forResource:)
locates a file in Resources and loads it into a Data
instance. This uses decode.url(forResource:)
internally.
And third, decode(_:as:)
locates a JSON file, loads it into a Data
instance, then decodes it to a Decodable
type of your choosing. This uses decode.data(forResource:)
internally, which in turn uses decode.url(forResource:)
.
For example, this project contains some JSON in Resources/quotes.json, so we can display its contents using the below:
if let quotes = decode("quotes.json", as: [String].self) {
ForEach(quotes) { quote in
Quote {
quote
}
}
}
The only limit to our realization of tomorrow will be our doubts of today.
It is never too late to be what you might have been.
You must be the change you wish to see in the world.
Tip: This page uses a custom theme, which is dark.
Created in Swift with Ignite