Post

Replies

Boosts

Views

Activity

navigate to another view Swiftui
i have NavigationView in my code i do this for button it Navigation       Button{         print("")       }label: {         Image(systemName: "list.dash")           .foregroundColor(.gray)       }     } how i can navigate to another view when user click the button??
1
1
7.9k
Nov ’22
torch level
why the setTorchModeOn not working? it not change the level torch     guard let device = AVCaptureDevice.default(for: .video) else { return }     if device.hasTorch {       do {         try device.lockForConfiguration()         try device.setTorchModeOn(level: 0.1)         if on == true {           device.torchMode = .on         } else {           device.torchMode = .off         }         device.unlockForConfiguration()       } catch {         print("Torch could not be used")       }     } else {       print("Torch is not available")     }   }
1
1
686
Nov ’22
recycling of list cells swiftui on scroll data
In my SwiftUI app, I have a data from an array. While scrolling through the list, the cells are being recycled, which is great. However, I'm puzzled because it seems that the data isn't being refetched as I scroll, which is contrary to what I expected. I want to understand why the data isn't being refetched for recycled cells and if this is expected behavior. class HistoryViewModel: ObservableObject { @Published var filteredContacts: [HistoryData] = [] func updateFilteredContacts() { filteredContacts = HistoryCallDataService().savedEntities if self.searchText.isEmpty { self.filteredContacts = filteredContacts } else { self.filteredContacts = filteredContacts.filter { contact in contact.firstName?.localizedCaseInsensitiveContains(self.searchText) ?? false || contact.lastName?.localizedCaseInsensitiveContains(self.searchText) ?? false || contact.telephone?.localizedCaseInsensitiveContains(self.searchText) ?? false } } } The List: List{ ForEach(vm.filteredContacts.reversed()) { item in HStack{ VStack(alignment: .leading){ Text("\(item.firstName ?? "N/A") \(item.lastName ?? "N/A" )") .fontWeight(.semibold) Text("\(item.telephone ?? "N/A")") .fontWeight(.medium) .padding(.top,1) } Spacer() VStack(alignment: .trailing){ Text("\(item.time ?? "N/A")") .fontWeight(.medium) Text("\(item.callHidden ? "Hidden" : "Normally ")") .foregroundColor(item.callHidden ? Color.theme.red : Color.theme.black) .fontWeight(.bold) .padding(.top,1) } } } } i attach image: https://im.ezgif.com/tmp/ezgif-1-db6ebe2a2e.gif [https://im.ezgif.com/tmp/ezgif-1-db6ebe2a2e.gif)
0
1
1k
Aug ’23
How to Prevent App Intents from Appearing in the Shortcuts App in SwiftUI Interactive Widgets
I'm working on a SwiftUI interactive widget using AppIntent. However, I want to prevent my AppIntents from appearing in the Shortcuts app. Currently, all my AppIntents are showing up in the Shortcuts app, but I only want them to be used within my widget. Is there a way to restrict the visibility of AppIntents so they don't appear in the Shortcuts app? Here is a simplified version of my AppIntent: import AppIntents struct MyWidgetIntent: AppIntent { static var title: LocalizedStringResource = "My Widget Intent" func perform() async throws -> some IntentResult { // Intent logic here } } I've looked into the documentation but haven't found a clear way to achieve this.
1
0
957
Aug ’24
Content Filter Permission Prompt Not Appearing in TestFlight
I added a Content Filter to my app, and when running it in Xcode (Debug/Release), I get the expected permission prompt: "Would like to filter network content (Allow / Don't Allow)". However, when I install the app via TestFlight, this prompt doesn’t appear at all, and the feature doesn’t work. Is there a special configuration required for TestFlight? Has anyone encountered this issue before? Thanks!
1
0
288
Jan ’25
Calling from Watchos
I am working with a watchOS app in SwiftUI, and I am using the following code to dial a phone number from the watch: var number = "123456789" if let telURL = URL(string: "tel:\(number)") { let wkExtension = WKExtension.shared() wkExtension.openSystemURL(telURL) } The issue is that when I try to dial a number starting with a * (asterisk) or # (hash), it doesn't work. When dialing a regular number, it works fine. Is there any way to get this to work?
1
0
117
Apr ’25
Instance member 'present' cannot be used on type 'Service'
class Service: UIViewController {       static func showError(_ message:String) {     // Create new Alert     let dialogMessage = UIAlertController(title: "Error", message: message, preferredStyle: .alert)           // Create OK button with action handler     let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in       print("Ok button tapped")     })           //Add OK button to a dialog message     dialogMessage.addAction(ok)     // Present Alert to     self.present(dialogMessage , animated: true, completion: nil)         } } why i get error in this line: self.present(dialogMessage , animated: true, completion: nil) the error: Instance member 'present' cannot be used on type 'Service' why?
1
0
1.3k
Jun ’22
function not transfer to vc
I made an extension to UIViewController and inside i have function I use several times: extension UIViewController {   func transitionToHomeVC() {     let homeViewController = self.storyboard?.instantiateViewController(withIdentifier: NameConstants.StoryBoard.homeViewController) as? HomeViewController     self.view.window?.rootViewController = homeViewController     self.view.window?.makeKeyAndVisible()   } } And I have a registration button and as soon as you click if the information was received and correct and etc ... then he has to move me at the to the HomeViewController screen and he does not do it. He does all the actions but does not pass to screen. @IBAction func signUpTapped(_ sender: Any) {     // Validate the fields     let error = validDataFields()     if error != nil {       // There's something wrong with the fields, show error message       Service.showError(vc: self, message: error!)     }     else {       // Create cleaned versions of the data       let fireName = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)       let lastName = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)       let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)       let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)            // Create the user       Auth.auth().createUser(withEmail: email, password: password) { resulte, err in         // Check for errors         if err != nil {           // There was an error creating the user           Service.showError(vc: self, message: "Error creating user \n make sure you enter: \n current email")         }         else {           // User was created successfully, now store the first name and last name           let db = Firestore.firestore()           db.collection("users").addDocument(data: ["firstName":fireName,"lastName":lastName, "uid": resulte!.user.uid]) { error in             if error != nil {               // Show error message               Service.showError(vc: self, message: " Error saving user Data")             }           }           self.transitionToHomeVC()         }       }     }   }     why it not move to homeViewController?
8
0
980
Jul ’22
Swipe the table view swipe not disappear
why when i Swipe the table view the swipe not disappear? see screenshot It just gets stuck like that and won't come back, why?  func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {     let item = realArray[indexPath.row]     let callAction = UIContextualAction(style: .normal, title: "Call Private", handler: { (action, view, success) in       self.service.dialNumber(number: item.telephone, prefixNumber: true)       self.service.setupCallerId(firstName: item.firstName, lastName: item.lastName, telephone: item.telephone)     })     callAction.backgroundColor = .systemGreen     let configuration = UISwipeActionsConfiguration(actions: [callAction])     return configuration   }
0
0
474
Oct ’22
change color background with button
i created a list with colors and i want when the user click red so all the screen was background red, if user click green so full background is green... i don't know why but the var not change..   var body: some View {           NavigationView {       List {         Section {           ScreenColorButtons(text: "Red", color: .red)           ScreenColorButtons(text: "Green", color: .green)           ScreenColorButtons(text: "Blue", color: .blue)         }       }     }   } } struct ScreenColorButtons: View {       @State static var screenSelected: Color = Color.red       var text: String   var color: Color       var body: some View{     Button(action: {       ScreenColorButtons.screenSelected = color       print(ScreenColorButtons.screenSelected)     }, label: {       NavigationLink(text){}     })   } } the ScreenColorView: struct ScreenColorView: View {   @Environment(\.presentationMode) var presentationMode       var body: some View {     Color.ScreenColorButtons.screenSelected   } } why the var not change and error to background??? thank for answer
3
0
1.7k
Nov ’22
refresh list coredata swifui
i maked core data and i fetch all data to List. all working (add ,delete) but! if the app inactive (to background) and i open again to delete a row it crashes with error: "Thread 1: "An NSManagedObjectContext cannot delete objects in other contexts." struct HistoryView: View {   @State private var history: [HistoryList] = [HistoryList]()   let coreDM: CoreDataManager       var dateFormatter: DateFormatter {     let formatter = DateFormatter()     formatter.dateFormat = "MM-dd-yyyy HH:mm"     return formatter   }       private func populateHistory(){     history = coreDM.getAllHistory()   }       var body: some View {     NavigationView{       VStack {         if !history.isEmpty {           List {             ForEach(history, id: \.self) { historyList in               HStack {                 Text(dateFormatter.string(from: historyList.dateFlash ?? Date(timeIntervalSinceReferenceDate: 0)))                 Text("\(historyList.timerFlash)s")                   .multilineTextAlignment(.trailing)                   .frame(maxWidth: .infinity, alignment: .trailing)               }             }.onDelete(perform: { indexset in               indexset.forEach { index in                 let history = history[index]                 coreDM.deleteHistory(history: history)                 populateHistory()               }             })           }.refreshable {             populateHistory()             print("## Refresh History List")           }         } else {           Text("History Flashlight is Empty")         }       }       .onAppear {         populateHistory()         print("OnAppear")       }     }.navigationTitle("History Flashlight")       .navigationBarTitleDisplayMode(.inline)   } } struct HistoryView_Previews: PreviewProvider {   static var previews: some View {     HistoryView(coreDM: CoreDataManager())   } } why?
0
0
1.1k
Nov ’22