Post

Replies

Boosts

Views

Activity

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
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
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 is throw an error as "Return from initializer without initializing all stored properties" in SwiftUI?
I have simple app in SwiftUI, when I use  @Binding var show : Bool for second register screen, it is throw an error for this line of code   init(state: AppState) {             self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           } as a "Return from initializer without initializing all stored properties" any idea? first screen: import SwiftUI struct RegisterFirstScreen: View {   @Binding var show : Bool   init(state: AppState) {             self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)     }   var body: some View {    NavigationLink(destination: RegisterSecondScreen(state: viewModel.state, show: $show),                            isActive: self.$pushActive) {                 Button {                              viewModel.signUp()                                     } label: {                   Text("Register Now")                     .padding()                    }               } } second screen: struct RegisterSecondScreen: View {   @ObservedObject var state: AppState       @Binding var show : Bool   var body: some View { Text("Next main screen") }}
2
0
2.7k
Mar ’22
why HStack items not alignnment in SwiftUI?
I have simple project in swiftUI, everythings is work, but HStack for  Rectangle() as I mention below, do not alignment the Rectangle and text at the same line, and idea will be appreciated. struct App: View {   var body: some View {         GeometryReader{g in              ZStack {         ForEach(0..data.count) { i in           DrawShape(center: CGPoint(x:g.frame(in: .global).width/2, y: g.frame(in: .global).height/2), index: i)         }              }     }     .frame(height: 200)          .clipShape(Circle())     .shadow(radius: 10)         VStack{       ForEach(data) { i in         HStack {                     Text(i.name)             .frame(width:100)             .padding()                      GeometryReader { g in             HStack{               Spacer(minLength: 0)               Rectangle()                 .fill(i.color)                 .frame(width: self.getWidth(width: g.frame(in: .global).width, value: i.percent) ,height: 10)                                              Text(String(format: "\(i.percent)", "%.0f"))                 .fontWeight(.bold)                 .padding(.leading,10)                 .frame(width:80)                Spacer()                                            }.frame(width: 240, height: 30)                                      }                     }                 }       .padding()       Spacer()     }                       }   func getWidth(width: CGFloat, value: CGFloat) - CGFloat {     let temp = value / 100     return temp * width   } }
3
0
3.3k
May ’21
How we can use userInteractionEnabled in (number.name) for number only?
I have number.name array like 1.go, 2.java, 3.swift etc..and I do not want to edit the number again, user will only change name. Is it possible?   if words.count == 24 {         for (index, textField) in textFields.enumerated() {           textField.delegate = self           textField.firstDesign()           textField.text = "\(index + 1). \(words[index])"           mneArr.append(words[index])         }
3
0
495
Jul ’21
How can I use the searchable feature for my row data in SwiftUI?
I have data in row like  Text(data.user) and I want to use searchable for it, I can use search bar, bat I want to use filter for user.    Text(data.user)                   .searchable(text: $searchText, placement: .navigationBarDrawer) like here, tere is some example for filter, but how can I use it for my data. Any idea? .onChange(of: searchText) { searchText in       if !searchText.isEmpty {         articles = sampleArticles.filter { $0.title.contains(searchText) }     } else {         articles = sampleArticles     } }
3
0
553
Sep ’21
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 can I use multiple `.alert` dialog in SwiftUI?
I have multiple alert dialog in project, just one of them is work, but I am still do not know why I am not use second one, so how we can use multiple .alert dialog in SwiftUI? struct MyView: View { @State private var selectedUsers: MyModel?   @State var datas: [MyModel]    @State private var deleteRow = false   @State private var deleteRows = false var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: {     deleteRow = true }) { Text("delete") } Button(action: {    deleteRows = true }) { Text("delete") } } .onTapGesture { selectedUsers = data }   .alert(isPresented: $deleteRow) {               Alert(title: Text("title"),                 message: Text("message"),                 primaryButton: .destructive(Text("Delete")) {                                 self.delete(item: data)                                   },                 secondaryButton: .cancel())             }   .alert(isPresented: $deleteRows) {               Alert(title: Text("title"),                 message: Text("message"),                 primaryButton: .destructive(Text("Delete")) {                    self.datas.removeAll()                 },                 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) } }}
3
1
2.2k
Mar ’22
Value of type 'Text' has no member 'searchable'
I want to use searchbar for name, but it is throw an arror like " Value of type 'Text' has no member 'searchable'" any idea?   @State private var searchText = ""    Text(data.name)                 .font(.custom("Helvetica Neue", size: 14))                 .searchable(text: $searchText)
4
0
2.8k
Aug ’21
Trailing closure passed to parameter of type 'Int' that does not accept a closure
I have TabView in ContentView and I want to add TabView for OnboardingView in OtherView, every things work, but it is throw error for TabView in OtherView like "Trailing closure passed to parameter of type 'Int' that does not accept a closure" I do not know why? Any idea? ContentView: struct TabView : View {       var body: some View{           VStack(spacing: 0){ ....... } OtherView:    VStack {     TabView {       ForEach(onboardingData) { onboardingItem in          OnboardingCard(onboardingItem: onboardingItem)       }   }   .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))   .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode:   .always))   .foregroundColor(.white) }
4
1
6.6k
Aug ’21