Post

Replies

Boosts

Views

Activity

Why it says "Function is unused" in SwiftUI?
I have SwiftUI project, and I want to use register for my project, it throw an error as a "Function is unused" for signUp in this line of code: Button {                   self.viewModel.signUp                    } label: {                   Text("Register")                     .padding()                 } I do not know why? struct Register: View {       @ObservedObject private var viewModel: RegisterViewModel   @State var pushActive = false         init(state: AppState) {           self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)           }     var body: some View {    Button {                              self.viewModel.signUp                                     } label: {                   Text("Register")                     .padding()                                     } } viewmodel: class RegisterViewModel: ObservableObject {   @Published var email: String = ""   @Published var password: String = ""   @Published var state: AppState       private var cancellableBag = Set<AnyCancellable>()   private let authAPI: AuthAPI       init(authAPI: AuthAPI, state: AppState) {     self.authAPI = authAPI     self.state = state   }       func signUp() {     authAPI.signUp(email: email, password: password)       .receive(on: RunLoop.main)       .map(resultMapper)       .store(in: &cancellableBag)   } } }
1
0
4.1k
Mar ’22
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
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
Why list menu items not shown in SwiftUI project?
I have list item menu project in SwiftUI, my project work, but I have list icons, they are not shown in list view, even I was try to use system image, there is not any change on screen, any idea? struct MasterView: View { let view1 = Menu(name:"Home", image:"image_home", destination:.home) let view2 = Menu(name:"View 1", image:"image_view1", destination:.view1) let view3 = Menu(name:"View 3", image:"image_view2", destination:.view2) var body: some View { let menus: [Menu] = [view1, view2, view3] return List { ForEach(menus) { menu in self.destinationView(menu: menu) }}} func destinationView(menu: Menu) - some View { switch menu.destination { case .view1: return NavigationLink( destination: AnyView(View1(menu: menu)) ) { Text("\(menu.name)") } case .view2: return NavigationLink( destination: AnyView(View2(menu: menu)) ) { Text("\(menu.name)") } default: return NavigationLink( destination: AnyView(HomeView(menu: menu)) ) { Text("\(menu.name)") }}}} Model.swift: /// Main menu item for the list struct Menu: Identifiable { var id = UUID() var name: String var image: String var destination: ViewType } enum ViewType { case home case view1 case view2 }
5
0
1.6k
Apr ’21
SwiftUI: Change List row Highlight colour when tapped
The default colour of a list row when tapped is grey. I try many solution on stackoverflow and apple form, I did not solve problem, any idea? RecentRowView: struct RecentRowView: View {         var body: some View {            HStack(spacing: 15){       List{         NavigationLink(destination: SecondView()                           ){                 VStack{         HStack{             VStack(alignment: .leading, spacing: 8, content: {                             Text(recent.name)                 .font(.custom("Helvetica Neue", size: 14))                               })           Spacer(minLength: 10)           ZStack {                 }           }  }          }         }        }     }    }
1
0
4.0k
Sep ’21
Change icons border when click the bottom tab bar in Swift
I have custom bottom navigation bar in IOS application, everythings work very well, and I want to change bottom navigation items tint color when I click the items, and I was use the self.imgView.image!.withRenderingMode(.alwaysTemplate) self.imgView.tintColor = .red in isSelected, and it is change whole icons border tint color. I do not know where I miss, any idea? RootStackTabViewController: class RootStackTabViewController: UIViewController { @IBOutlet weak var bottomStack: UIStackView! var currentIndex = 0 lazy var tabs: [StackItemView] = { var items = [StackItemView]() for _ in 0..<5 { items.append(StackItemView.newInstance) } return items }() lazy var tabModels: [BottomStackItem] = { return [ BottomStackItem(title: "Home", image: "home"), BottomStackItem(title: "Favorites", image: "heart"), BottomStackItem(title: "Search", image: "search"), BottomStackItem(title: "Profile", image: "user"), BottomStackItem(title: "Settings", image: "settings") ] }() override func viewDidLoad() { super.viewDidLoad() self.setupTabs() } func setupTabs() { for (index, model) in self.tabModels.enumerated() { let tabView = self.tabs[index] model.isSelected = index == 0 tabView.item = model tabView.delegate = self self.bottomStack.addArrangedSubview(tabView) } } } StackItemView: protocol StackItemViewDelegate: AnyObject { func handleTap(_ view: StackItemView) } class StackItemView: UIView { @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var imgView: UIImageView! @IBOutlet weak var highlightView: UIView! private let higlightBGColor = UIColor(hexString: "1160FB") static var newInstance: StackItemView { return Bundle.main.loadNibNamed( StackItemView.className(), owner: nil, options: nil )?.first as! StackItemView } weak var delegate: StackItemViewDelegate? override func awakeFromNib() { super.awakeFromNib() self.addTapGesture() } var isSelected: Bool = false { willSet { self.updateUI(isSelected: newValue) self.titleLabel.textColor = UIColor.white self.imgView.image!.withRenderingMode(.alwaysTemplate) self.imgView.tintColor = .red } } var item: Any? { didSet { self.configure(self.item) } } private func configure(_ item: Any?) { guard let model = item as? BottomStackItem else { return } self.titleLabel.text = model.title self.imgView.image = UIImage(named: model.image) self.isSelected = model.isSelected } private func updateUI(isSelected: Bool) { guard let model = item as? BottomStackItem else { return } model.isSelected = isSelected let options: UIView.AnimationOptions = isSelected ? [.curveEaseIn] : [.curveEaseOut] UIView.animate(withDuration: 0.4, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: options, animations: { self.titleLabel.text = isSelected ? model.title : "" let color = isSelected ? self.higlightBGColor : .white self.highlightView.backgroundColor = color (self.superview as? UIStackView)?.layoutIfNeeded() }, completion: nil) } } extension StackItemView { func addTapGesture() { let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleGesture(_:))) self.addGestureRecognizer(tapGesture) } @objc func handleGesture(_ sender: UITapGestureRecognizer) { self.delegate?.handleTap(self) } }
1
0
1.1k
Jul ’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