Get your own website
Demo.swift
ContentView.swift
App.swift
 
import SwiftUI
import Foundation

struct AppGroupDemo: View {
  private let suite = UserDefaults(suiteName: "group.com.example.notes")!
  @State private var count: Int = 0
  var body: some View {
    VStack(spacing: 12) {
      Text("Notes count: \(count)")
      HStack {
        Button("Increment") { count += 1; suite.set(count, forKey: "notesCount") }
        Button("Load") { count = suite.integer(forKey: "notesCount") }
        Button("Clear") { suite.removeObject(forKey: "notesCount"); count = 0 }
      }
    }
    .task { count = suite.integer(forKey: "notesCount") }
    .padding()
  }
}

                    
import SwiftUI

struct ContentView: View {
  var body: some View {
    AppGroupDemo()
  }
}

                    
import SwiftUI

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}