ObjectUI

1.3.0

Create SwiftUI Views with any data; Prefer using https://github.com/0xOpenBytes/CacheStore
0xLeif/ObjectUI

What's New

1.3.0

2021-08-07T03:04:54Z

1.3.0

1.2.0

1.1.0

1.0.1

1.0.0

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)
                }
            }
        }
    }
}

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)
                }
            }
        }
    }
}

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Sun Mar 31 2024 00:56:46 GMT-0900 (Hawaii-Aleutian Daylight Time)