https://github.com/3sidedcube/fusion
JSON data driven UITableView UI for iOS fetched from a remote API using UIKit
https://github.com/3sidedcube/fusion
Last synced: 8 months ago
JSON representation
JSON data driven UITableView UI for iOS fetched from a remote API using UIKit
- Host: GitHub
- URL: https://github.com/3sidedcube/fusion
- Owner: 3sidedcube
- Created: 2021-03-09T14:55:04.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-09-01T09:13:45.000Z (almost 3 years ago)
- Last Synced: 2025-01-30T01:22:30.697Z (over 1 year ago)
- Language: Swift
- Size: 477 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fusion
A Swift Package (library) that renders JSON data into SwiftUI views.
## Basic usage
```swift
struct MyView: View {
var body: some View {
JSONView(url: ...)
}
}
```
## How it works
For every UI component that could be represented as a JSON object, a `FusionModel` is created like:
```swift
struct FusionText: FusionModel {
var value: String
var isMarkdown: Bool?
...
}
```
Since a `FusionModel` is `Decodable`, this can be decoded from a JSON such as:
```json
{
"type": "Text",
"value": "Hello 👋",
"isMarkdown": false,
...
}
```
Fusion decodes the JSON into its corresponding model using the `type` property.
It's matched to a model type in the `Fusion.shared.models` property.
Since a `FusionModel` is also a `View`, it can then be rendered into UI.
A similar logic applies to `FusionAction`s, except they are rendered as `ViewModifiers`.
The models in this library are prefixed with the `"Fusion*"` suffix to not interfere with the SwiftUI types.
## Supported types
* View
* Text
* Image
* Stack
* Scroll
* Screen
The `View` properties can be applied to all models.
## Make a custom model
Make your own (view) model:
```swift
struct MyModel: FusionModel {
var myProperty: String
...
var body: some View {
...
}
}
```
and register it on the `Fusion`:
```swift
Fusion.shared.models["MyModel"] = MyModel.self
```
## What motivated the name "Fusion"?
Fusion here means to bring together two platforms, iOS and Android, powered by a single data source.
For web-server apps, the business logic should sit server-side as much as possible.
Fusion aims to be as simple as "server tell me what to draw and I'll draw it".
## Legacy
This framework was initially developed (and nearly finished) in UIKit. The work can be found in the branch: `legacy/ui-kit`.