I will try this out! Thanks!
Post
Replies
Boosts
Views
Activity
I realize that this is the same situation I dealt with in my original post...I’ll start a new thread
Edit: New thread - https://developer.apple.com/forums/thread/670912
Not on there. This is what it's suggesting:
Similar solutions…
How to handle unknown properties and methods using @dynamicMemberLookup
How to create a project using Swift Package Manager
How to fix “argument of #selector refers to instance method that is not exposed to Objective-C”
How to install a beta version of Swift
How to subclass UIApplication using UIApplicationMain
I don't think that any of these correlate with my JSON problem, but please correct me if I'm wrong.
I found a Hacking with Swift page (hackingwithswift.com/example-code/language/how-to-convert-json-into-swift-objects-using-codable) showing how to convert JSON into Swift objects. It's pretty straightforward, though, I need to figure out how to convert cardsInfo to JSON, if at all, and if that's what I need to convert.
Good to know. Thank you!
...you should better consider using Coding. With making CardInfo conform to Codable, you can easily convert whole Array of CardInfo into Data.
And Data can be easily writable to a file. Where should I start with this? Or should I just Google something like "convert whole array to data codable?"
Works...thank you so much!
This works! Thank you!
Please show your latest code if you cannot solve the issue yourself. ContentView:
//
// ContentView.swift
// Shared
//
// Created by Joshua Srery on 12/17/20.
// Additional code by OOPer on Apple Developer Forums
//
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var systemColorScheme
@State var myColorScheme: ColorScheme?
var body: some View {
TabView {
CardsView()
.tabItem {
Image(systemName: "person.crop.square.fill.and.at.rectangle")
Text("Cards")
}
SettingsView(colorScheme: $myColorScheme)
.tabItem {
Image(systemName: "gear")
Text("Settings")
}
}
.colorScheme(myColorScheme ?? systemColorScheme)
}
}
SettingsView:
//
// SettingsView.swift
// Lunch Card (iOS)
//
// Created by Joshua Srery on 12/21/20.
// Additional code by OOPer on Apple Developer Forums.
//
import SwiftUI
struct SettingsView: View {
@State private var selectedAppearance = 1
@Binding var colorScheme: ColorScheme?
var body: some View {
NavigationView {
Form {
Section(header: Text("Customization")) {
Picker(selection: $selectedAppearance, label: Text("Appearance")) {
Text("System Default").tag(1)
Text("Light").tag(2)
Text("Dark").tag(3)
}
.onAppear {
switch colorScheme {
case .none:
selectedAppearance = 1
case .light:
selectedAppearance = 2
case .dark:
selectedAppearance = 3
default:
break
}
}
.onChange(of: selectedAppearance) { value in
//print(selectedAppearance)
switch selectedAppearance {
case 1:
//print("System Default")
colorScheme = nil
case 2:
//print("Light")
colorScheme = .light
case 3:
//print("Dark")
colorScheme = .dark
default:
break
}
}
///...
}
So I tried this out, and I have a feeling it would work if $selectedAppearance actually changed. I added the new code but now when I try to select Light or Dark, it just dismisses and defaults to System Default. I may have missed something, so please acknowledge that.
This could help I probably should've been more clear.
I took a glance at these and saw that they weren't using the SwiftUI Lifecycle (No App/SceneDelegates).
It's possible that I might've missed something, and correct me if I'm wrong.
Please try. This worked! Thank you so much! 😊
This didn't work.
I put showSheetView into a shared object, SheetInfo, and called it in both CardsView and AddView as sheetInfo. I changed every declaration of $showSheetView to $sheetInfo.showSheetView. Still didn't work. Is there something I missed? Here's the code:
SheetInfo:
class SheetInfo: ObservableObject {
@Published var showSheetView = false
}
CardsView:
struct CardsView: View {
@StateObject var cardsInfo = CardsInfo()
@StateObject var sheetInfo = SheetInfo() // <-
@State private var editMode = EditMode.inactive
var body: some View {
(...)
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
self.sheetInfo.showSheetView.toggle()
}) {
Image(systemName: "plus")
}.sheet(isPresented: $sheetInfo.showSheetView) {
AddView(cardsInfo: cardsInfo, sheetInfo: sheetInfo, isShowing: $sheetInfo.showSheetView)
}
}
(...)
}
AddView:
struct AddView: View {
@ObservedObject var cardsInfo: CardsInfo
@ObservedObject var sheetInfo: SheetInfo
@Binding var isShowing: Bool
var body: some View {
(...)
Button(action: {
cardsInfo.add()
isShowing = false
}) {
Text("Create")
.bold()
}
(...)
}
This works! But...I need the Create button to dismiss the AddView sheet. I tried adding showSheetView to a shared object but @State is not allowed there. I tried changing it to @Published but it changed nothing.
I will try this out! Thank you!