Post

Replies

Boosts

Views

Activity

Not append new data in an array
Hi I want to add new data to a list in my project but I can't do it I have a ContentView.swift view for showing products list and in another view (ShopView) I want to add data to products array My products array and my addProduct() function in the Products.swift file Please help me Thanks ContentView.swift struct ContentView: View {     @ObservedObject var cart = Products()     var body: some View {         NavigationView{             List {                 ForEach(cart.products) { product in                     Text("\(product.name) \(product.price)$")                 }             }             .navigationBarItems(                 trailing: NavigationLink(destination: Shop()) {                     Text("Go Shop")                 })             .navigationBarTitle("Cart")         }     } } Product.swift struct Product: Identifiable {     var id = UUID()     var name: String     var price: Int } Products.swift struct Shop: View {     @ObservedObject var cart = Products()     var body: some View {         VStack{             Button("Add Product To Cart") {                 cart.addProduct(product: Product(name: "Name", price: 399))             }         }     } } Products.swift class Products: ObservableObject {     @Published var products = [Product]()     func addProduct(product: Product) {         products.append(product)         print("Product Added")     } }
1
0
1.9k
May ’21
SafeAreaInsets Size for SwiftUI padding
i already used .padding(.top, UIApplication.shared.windows[0].safeAreaInsets.top) but in swiftui 3 and iOS 15 i got this warning 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead so in new version what is the best way for getting safe area insets? i can't use GeometryRedaer
1
0
7.3k
Jan ’22
SwiftUI - Show alert when go to new page
I  want an alert to be displayed when the user is moved to a new page without any action and quickly. I use NavigationLink I try for this @State private var showAlert = true but there was no result you can help me ?
Replies
3
Boosts
0
Views
2.6k
Activity
May ’21
Not append new data in an array
Hi I want to add new data to a list in my project but I can't do it I have a ContentView.swift view for showing products list and in another view (ShopView) I want to add data to products array My products array and my addProduct() function in the Products.swift file Please help me Thanks ContentView.swift struct ContentView: View {     @ObservedObject var cart = Products()     var body: some View {         NavigationView{             List {                 ForEach(cart.products) { product in                     Text("\(product.name) \(product.price)$")                 }             }             .navigationBarItems(                 trailing: NavigationLink(destination: Shop()) {                     Text("Go Shop")                 })             .navigationBarTitle("Cart")         }     } } Product.swift struct Product: Identifiable {     var id = UUID()     var name: String     var price: Int } Products.swift struct Shop: View {     @ObservedObject var cart = Products()     var body: some View {         VStack{             Button("Add Product To Cart") {                 cart.addProduct(product: Product(name: "Name", price: 399))             }         }     } } Products.swift class Products: ObservableObject {     @Published var products = [Product]()     func addProduct(product: Product) {         products.append(product)         print("Product Added")     } }
Replies
1
Boosts
0
Views
1.9k
Activity
May ’21
SafeAreaInsets Size for SwiftUI padding
i already used .padding(.top, UIApplication.shared.windows[0].safeAreaInsets.top) but in swiftui 3 and iOS 15 i got this warning 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead so in new version what is the best way for getting safe area insets? i can't use GeometryRedaer
Replies
1
Boosts
0
Views
7.3k
Activity
Jan ’22
Xcode 15 Beta Simulator Problems
I just downloaded Xcode 15 beta from Apple Developer website and I chose iOS 17 SDK/Simulator to download too. But now after creating a project and running it on a simulator my Xcode doesn't detect iOS 17 SDK. I also moved the "simruntime" file to Library/Developer/CoreSimulator/Profiles folder.
Replies
0
Boosts
0
Views
937
Activity
Jun ’23