Post

Replies

Boosts

Views

Activity

Why NavigationLink not work for text button in SwiftUI?
I have text button, and I want to use navigation link in this project, but it is not work when I click the button? Any idea?   @State var isLink = false       var body: some View {     GeometryReader { geometry in         ZStack {    NavigationLink(destination: SecondView(), isActive: $isLink) {                 Button() {                   self.isLink = true                 } label: {                                       Text("Button")                     .padding()                     .frame(width: 250, height: 50, alignment: .center)                     .foregroundColor(Color.white)                     .background(Color("color"))                     .clipShape(Capsule())                  }}}}
1
0
491
Feb ’22
Why it is throw an error as "'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead" in SwiftUI?
I have project in SwiftUI 2.0 but when I update to SwiftUI 3.0 it is throw an error for windows as a windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead any idea?     .padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top)
0
0
668
Feb ’22
How To Show A SwiftUI Onboarding Screen Only When To App Launches For The First Time
I want to use onboarding screen in my project, and it is work but I want to use it just once time for app, I do not know how I will do it, is there any way? struct ContentView: View {   @State private var onboardinDone = false   var data = OnboardingData.data       var body: some View {     Group {       if !onboardinDone {         OnboardingView(data: data, doneFunction: {                              print("done onboarding")         })       } else {         MainScreen()       }     }   }        } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
2
1
2k
Sep ’23
why it is throw an error as a Value of type 'ContentView' has no member 'restaurants' in SwiftUI?
I have example of swiftUI project, and it is throw an error as a "Value of type 'ContentView' has no member 'restaurants'" for    self.restaurants.remove(atOffsets: indexSet) } line of code, I do not know what I missed, any idea? import SwiftUI struct ContentView: View {          @State private var selectedRestaurant: Restaurant?       var body: some View {     List {       ForEach(restaurants) { restaurant in         BasicImageRow(restaurant: restaurant)           .contextMenu {                           Button(action: {               // mark the selected restaurant as check-in               self.checkIn(item: restaurant)             }) {               HStack {                 Text("Check-in")                 Image(systemName: "checkmark.seal.fill")               }             }                           Button(action: {               // delete the selected restaurant               self.delete(item: restaurant)             }) {               HStack {                 Text("Delete")                 Image(systemName: "trash")               }             }                           Button(action: {               // mark the selected restaurant as favorite               self.setFavorite(item: restaurant)             }) {               HStack {                 Text("Favorite")                 Image(systemName: "star")               }             }           }           .onTapGesture {             self.selectedRestaurant = restaurant           }           .actionSheet(item: self.$selectedRestaurant) { restaurant in                           ActionSheet(title: Text("What do you want to do"), message: nil, buttons: [                               .default(Text("Mark as Favorite"), action: {                 self.setFavorite(item: restaurant)               }),                               .destructive(Text("Delete"), action: {                 self.delete(item: restaurant)               }),                               .cancel()             ])           }       }       .onDelete { (indexSet) in         self.restaurants.remove(atOffsets: indexSet)       }     }   }       private func delete(item restaurant: Restaurant) {     if let index = self.restaurants.firstIndex(where: { $0.id == restaurant.id }) {       self.restaurants.remove(at: index)     }   }       private func setFavorite(item restaurant: Restaurant) {     if let index = self.restaurants.firstIndex(where: { $0.id == restaurant.id }) {       self.restaurants[index].isFavorite.toggle()     }   }       private func checkIn(item restaurant: Restaurant) {     if let index = self.restaurants.firstIndex(where: { $0.id == restaurant.id }) {       self.restaurants[index].isCheckIn.toggle()     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } struct BasicImageRow: View {   var restaurant: Restaurant       var body: some View {     HStack {       Image(restaurant.image)         .resizable()         .frame(width: 40, height: 40)         .cornerRadius(5)       Text(restaurant.name)               if restaurant.isCheckIn {         Image(systemName: "checkmark.seal.fill")           .foregroundColor(.red)       }               if restaurant.isFavorite {         Spacer()                   Image(systemName: "star.fill")           .foregroundColor(.yellow)       }     }   } } model: struct Restaurant: Identifiable {   var id = UUID()   var name: String   var image: String   var isFavorite: Bool = false   var isCheckIn: Bool = false } var restaurants = [ Restaurant(name: "Cafe Deadend", image: "cafedeadend"),        Restaurant(name: "Homei", image: "homei"),        Restaurant(name: "Teakha", image: "teakha"),        Restaurant(name: "Cafe Loisl", image: "cafeloisl"), ]
1
0
1.8k
Feb ’22
Why list items not able to delete in SwiftUI?
I have a simple app in SwiftUI, and I try to delete list items in app , project is working, but still list items not able to delete, I do not know what I did not put in my codes, any idea will be appreciated. struct MyView: View { @State private var selectedUsers: MyModel? var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text("delete") } } .onTapGesture { selectedUsers = data } } .onDelete { (indexSet) in selectedUsers.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }} model: struct MyModel: Identifiable, Hashable, Codable { var id = UUID().uuidString var name: String } var datas = [ MyModel(name: "david"), MyModel(name: "marry"), ]
3
0
2k
Feb ’22
How we can delete all list items in SwiftUI?
I have a simple app in SwiftUI, and I try to delete all list items with context menu , when I click context menu button, I want to remove all items, is it possible? struct MyView: View { @State private var selectedUsers: MyModel? var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text("delete") } } .onTapGesture { selectedUsers = data } } .onDelete { (indexSet) in selectedUsers.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }} model: struct MyModel: Identifiable, Hashable, Codable { var id = UUID().uuidString var name: String } var datas = [ MyModel(name: "david"), MyModel(name: "marry"), ]
2
0
1.7k
Feb ’22
How we can use alert menu before delete list items in SwiftUI?
I have list items in SwiftUI, and when I delete list items I want to delete after alert menu, like "do want to delete your list items, ""yes" or "no" is it possible? struct MyView: View { @State private var selectedUsers: MyModel? var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text("delete") } } .onTapGesture { selectedUsers = data } } .onDelete { (indexSet) in self.datas.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }}
2
0
2.5k
Jan ’23
How we can use alert menu before delete list items in SwiftUI?
I have list items in SwiftUI, and when I delete list items, but when I click the delete button, it delete item randomly, I want to delete seleted item, where is the mistake? struct MyView: View { @State private var selectedUsers: MyModel?   @State var datas: [MyModel]    @State private var confirmDelete = false var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text("delete") } } .onTapGesture { selectedUsers = data }   .confirmationDialog( "Are you sure ?",                   isPresented: $confirmDelete,                   titleVisibility: .visible                 ){                                       Button(role: .destructive) {                     self.delete(item: data)                   } label: {                     Text("ok")                                         }                   Button(role: .cancel) {                                         } label: {                     Text("cancel")                                         }                 }             } .onDelete { (indexSet) in self.datas.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }}
1
1
1k
Feb ’22
Why SwiftUI `confirmationDialog` delete the wrong item?
I am trying to use confirmationDialog to delete an item in a List. But what happens is that the wrong item gets deleted. Why? Here is my code: struct MyView: View { @State private var selectedUsers: MyModel?   @State var datas: [MyModel]    @State private var confirmDelete = false var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text("delete") } } .onTapGesture { selectedUsers = data }   .alert(isPresented: $confirmDelete) {               Alert(title: Text("title"),                 message: Text("message"),                 primaryButton: .destructive(Text("Delete")) {                                 self.delete(item: data)                                   },                 secondaryButton: .cancel())             }                               } .onDelete { (indexSet) in self.datas.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }}
1
1
1k
Oct ’22
Why it throw ab error as a "Cannot find 'state' in scope" in SwiftUI project?
I have small SwiftUI app, and it throw an error like "Cannot find 'state' in scope" for this line  Register(state: state) I guess it must be like that, but it is throw an error, I do not know what I missed? Any idea? struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel        init(state: AppState) {    self.viewModel =RegisterViewModel(authAPI: AuthService(), state: state)    }       var body: some View { } } struct Register_Previews: PreviewProvider {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false        init(state: AppState) {    self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)    }       static var previews: some View {     Register(state: state)   } } class RegisterViewModel: ObservableObject {     @Published var state: AppState       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }     } }
2
0
960
Mar ’22
why it say "Extra arguments at positions #3 , #4 in call" in SwiftUI?
I have small problem in my project, it throw an error as a Extra arguments at positions #3, #4 for  Auth.auth().signIn() line, I do not know what I missed? func login(email: String, password: String, name: String, surname: String) -> Future<User?, Never> { return Future<User?, Never> { promise in Auth.auth().signIn(withEmail: email, password: password, name: name, surname: surname) {(authResult, _) in guard let id = authResult?.user.providerID, let email = authResult?.user.email else { promise(.success(nil)) return } let user = User(id: id, email: email, name:name, surname:surname) promise(.success(user)) } } } model: import Foundation struct User { let id: String let email: String let name: String let surname: String }
1
0
768
Mar ’22
How to navigate from side menu in SwiftUI to new SwiftUI.
I have side bar menu in my project, it is work correctly, but I want to use every side bar option menu, when I click any side bar menu, it may router to other Swift UI. How can I create Swift UI for every side option menu? SideMenuViewModel: enum SideMenuViewModel: Int, CaseIterable { case profile case lists case bookmarks case messages var title: String { switch self { case .profile: return "Profile" case .lists: return "lists" case .bookmarks: return "bookmarks" case .messages: return "messages" }} var imageName: String { switch self { case .profile: return "profile" case .lists: return "list.bullet" case .bookmarks: return "bookmark" case .messages: return "message" }}} SideMenuView: struct SideMenuView: View { @Binding var isShowing: Bool var body: some View { ZStack { LinearGradient(gradient: Gradient(colors: [Color("red"), Color("blue")]), startPoint: .top, endPoint: .bottom) .ignoresSafeArea() VStack { SideMenuHeaderView(isShowing: $isShowing) .frame(height: 240) ForEach(SideMenuViewModel.allCases, id:\.self) { option in NavigationLink( destination: Text(option.title), label: { SideMenuOptionView(viewModel: option) })} Spacer() }}.navigationBarHidden(true) }}
0
0
811
Mar ’21
Using slide menu with bottom navigation bar
I have a simple slide menu project in SwiftUI, and I want to add bottom navigation bar in my project, but when I click the slide menu button, I want to draw bottom navigation bar as well like in image. - https://stackoverflow.com/questions/66693507/using-slide-menu-with-bottom-navigation-bar Any idea will be appreciated. Drawer: struct Home: View { // Hiding tab Bar... init() { UITabBar.appearance().isHidden = true } @StateObject var menuData = MenuViewModel() @Namespace var animation var body: some View { HStack(spacing: 0){ // Drawer And Main View... // Drawer... Drawer(animation: animation) // Main View... TabView(selection: $menuData.selectedMenu){ Catalogue() .tag("Catalogue") Orders() .tag("Your Orders") Cart() .tag("Your Cart") Favourites() .tag("Favourites") } .frame(width: UIScreen.main.bounds.width) } // Max Frame... .frame(width: UIScreen.main.bounds.width) // Moving View.... // 250/2 = 125.... .offset(x: menuData.showDrawer ? 125 : -125) .overlay( ZStack{ if !menuData.showDrawer{ DrawerCloseButton(animation: animation) .padding() } }, alignment: .topLeading ) // Setting As Environment Object.... // For Avoiding Re-Declarations... .environmentObject(menuData) } }
0
0
1k
Mar ’21
Thread 1: Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(_:) for msgDatas may be missing as an ancestor of this view.
It throw fatal error for data in "  self.data.selectedData = i", even I try to calling @State for solve, but nothing change. Main: struct Main : View {       @EnvironmentObject var data : msgDatas   @State var show: Bool = false       var body : some View{           List(msgs){i in               cellView(pic: i.pic, name: i.name, msg: i.msg, time: i.time, msgs: i.msgs).onTapGesture {                   self.data.selectedData = i         self.show.toggle()       }     }   } } cellView: struct cellView : View {       var pic : String   var name : String   var msg : String   var time : String   var msgs : String       var body : some View{           HStack(spacing: 15){               Image(pic).resizable().frame(width: 50, height: 50).clipShape(Circle())               VStack(alignment:.leading,spacing: 5){                   Text(name)         Text(msg).lineLimit(2)       }               Spacer()               VStack(spacing: 10){                   Text(time)         if msgs != ""{                       Text(msgs).padding(8).background(Color("bg")).foregroundColor(.white).clipShape(Circle())         }         else{                       Spacer()         }       }             }.padding(9)   } }
30
0
3.6k
Mar ’21
Destination view for multiple list item in SwiftUI
I have list item, and all item destination view routed to EndView, how can I add multiple destination view for every item, for example: when I click the first item it will open EndView, when I click the second item it will open NewView...., any idea will be appreciated. Option: struct InnerOptionValues: Codable {   var title: String   var image: String   var isAddSection: Bool   var isUseToggle: Bool   var headerTitle: String } extension Option {   static let listValues: [InnerOptionValues] = [     .init(title: "title1", image: "image1", isAddSection: true, isUseToggle: false, headerTitle: ""),     .init(title: "title2",image: "image2", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "title3", image: "image3", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "4", image: "image4", isAddSection: false, isUseToggle: false, headerTitle: ""),     .init(title: "5", image: "image5", isAddSection: false, isUseToggle: false, headerTitle: ""),   ]     InnerView: struct InnerView: View {   let value: InnerOptionValues       var body: some View {     return NavigationLink(destination: EndView(value: value)) {       HStack {         Image(value.image)           .resizable()           .frame(width: 16, height: 16)           .aspectRatio(contentMode: .fill)         Text(value.title)           .foregroundColor(.blue)           .font(.system(size: 18))       }     }   } } struct EndView: View {   let value: InnerOptionValues       var body: some View {     return NavigationLink(destination: EndView(value: value)) {               Text("Coming Soon!!!")         .font(.system(size: 25))         .foregroundColor(.blue)     } .navigationBarTitle(Text(value.title), displayMode: .inline)   } }
0
0
505
Apr ’21