Posts

Post not yet marked as solved
10 Replies
Oh ok it's a Mac App, I've never tried sorry.mine is iOS, and instanciating in the SceneDelegate class, it works just fineimport UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: ContentView(testObject: TestClass())). // Instanciation self.window = window window.makeKeyAndVisible() } }Perhaps I'll try a MacApp tomorrow and let you know, in France it's already the beginning of the night 😉
Post not yet marked as solved
10 Replies
In your code, there is no instanciation of the TestClass object so it's equal to nil and so the BAD_ACCESS errorTrystruct ContentView: View { @ObservedObject public var testObject = TestClass(). // Instanciation of the object var body: some View { Text(testObject.str).frame(maxWidth: .infinity, maxHeight: .infinity) } }And if the object is instanciated elsewhere for exampleimport SwiftUI public class TestClass: ObservableObject { @Published public var str: String = "Goodbye" } struct ContentView: View { @ObservedObject public var testObject: TestClass. // instanciated elsewhere, here in the call of the view var body: some View { Text(testObject.str).frame(maxWidth: .infinity, maxHeight: .infinity) } } struct Test_Previews: PreviewProvider { static var previews: some View { ContentView(testObject: TestClass()) // Instanciation } }
Post not yet marked as solved
3 Replies
for background colorList(0..<10) { item in Text(" item \(item)") } .colorMultiply(.green)for imageList(0..<10) { item in Text(" item \(item)") } .opacity(0.5) .background(Image(.........))
Post not yet marked as solved
7 Replies
struct TabViewColor: View { init() { UITabBar.appearance().backgroundColor = UIColor.red } var body: some View { TabView { ....... } }}Hope this helps!
Post marked as solved
4 Replies
var body: some View { ZStack { Color.blue } .edgesIgnoringSafeArea(.all) // comment if you don't want the blue background in safeArea on iPhone X and next }The view will have a blue backgroundColor.Working in Beta 6, but should work with previous too.Hope this helps!