Go to file
Zach Eriksen b2ad6e88ea
Merge pull request #4 from 0xLeif/develop
1.1.0
2021-06-24 19:58:28 -05:00
.github Added funding.yml 2021-06-24 18:48:50 -05:00
.swiftpm/xcode/package.xcworkspace/xcshareddata Initial Commit 2021-05-24 21:38:48 -05:00
Sources/ObjectUI Added conformance to Hashable 2021-06-24 19:48:01 -05:00
Tests/ObjectUITests Updated tests 2021-06-24 18:43:54 -05:00
.gitignore Removed Package.resolved file 2021-06-24 18:51:03 -05:00
LICENSE Create LICENSE 2021-06-24 19:00:53 -05:00
Package.swift 👊 commit 2021-05-24 21:48:14 -05:00
README.md Update README.md 2021-06-22 20:13:00 -05:00

README.md

ObjectUI

Create SwiftUI Views with any data

Usage

import ObjectUI

Basic Example

struct ContentView: View {
    var body: some View {
        ObjectView { object in
            VStack {
                if let value = object.value(as: String.self) {
                    Text(value)
                        .font(.largeTitle)
                } else {
                    Text("Waiting...")
                }
                
                Button("Wave") {
                    DispatchQueue.main.async {
                        object.set(value: "👋")
                    }
                }
            }
        }
    }
}

JSON Example

struct ContentView: View {
    let json = """
        {
          "userId": 1,
          "id": 2,
          "title": "quis ut nam facilis et officia qui",
          "completed": false
        }
        """
        .data(using: .utf8)
    
    var body: some View {
        ObjectView(data: json) { object in
            VStack {
                object.userId.value(as: Int.self).map { userId in
                    Text("\(userId)")
                }
                
                object.id.value(as: Int.self).map { id in
                    Text("\(id)")
                }
                
                object.title.value(as: String.self).map { title in
                    Text(title)
                }
                
                object.completed.value(as: Bool.self).map { completed in
                    Text(completed.description)
                }
            }
        }
    }
}