Post

Replies

Boosts

Views

Activity

open a New View from a item in a contextual menu
Bonjour as the title says: I have a contextual menu in my app, using swift, I want to open a New View from a item in a contextual menu when I click on the like to go to MainView, nothings happens Please Help me I am very new in IOS programmation here is my code so far: .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { NavigationLink(destination:MainView()){ Label("MainView", systemImage: "house") } Button(action: { // Show modal text for copyright }) { Label("Modal Text", systemImage: "text.book.closed") } Button(action: { // Go to HelpView }) { Label("HelpView", systemImage: "questionmark.circle") } } label: { Image(systemName: "house") } } } Thanks for helping me I have been fighting with this for hours David
8
0
839
Jul ’23
no sound with AVAudioPlayer in real device and simulator in Xcode 14
Bonjour I use this code in Xcode 14 import AVFoundation class Jouer{ var audioPlayer: AVAudioPlayer? func playAudio() { let sound=Bundle.main.url(forResource: "musique.mp3, withExtension: "mp3") guard let url = sound else { print("Audio file not found") return } if FileManager.default.fileExists(atPath: url.path) { print("Audio file exists") } else { print("Audio file not found") } do { let session = AVAudioSession.sharedInstance() try! session.setCategory(AVAudioSession.Category.playback) audioPlayer = try AVAudioPlayer(contentsOf: url) guard let audioPlayer = audioPlayer else { return } audioPlayer.prepareToPlay() audioPlayer.play() if audioPlayer.isPlaying { print("sound playing") } else { print("problem sound not playing") } } catch { print("Error playing audio: \(error.localizedDescription)") } } } there is no error but I can hear no sound no sound and volume is ok the file musique.mp3 is well in the project What am I missing? thanks for your help
3
0
1.5k
Mar ’23
Error Type '() -> ()' cannot conform to 'StringProtocol'
Bonjour I am new in swift and Xcode I want to use the search bar to fetch the titles following what is typed I get this error: Type '() -> ()' cannot conform to 'StringProtocol' import SwiftUI import SQLite3 struct ContentView: View { @State var cantiques = [[String: String]]() @State private var searchText = "" var body: some View { NavigationView { VStack { List(cantiques, id: \.self) { cantique in NavigationLink( destination: hymnesetlouangesafficher(cantique: cantique), label: { Text("\(cantique["ref"] ?? "") - \(cantique["titre"] ?? "")") }) } } .navigationTitle("Hymnes et Louanges") .searchable(text: $searchText) { searchText in fetchCantiqueTitles(searchText: searchText) } } .onAppear { fetchCantiqueTitles(searchText: "") } } func fetchCantiqueTitles(searchText: String) { cantiques.removeAll() var db: OpaquePointer? let dbPath = Bundle.main.path(forResource: "Hymnes_et_Louanges", ofType: "db")! if sqlite3_open(dbPath, &db) == SQLITE_OK { print("Database opened successfully") } else { print("Database not opened - problem") return } let query = "SELECT ref, titre FROM cantiques WHERE titre LIKE '%\(searchText)%'" var statement: OpaquePointer? if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK { while sqlite3_step(statement) == SQLITE_ROW { if let ref = sqlite3_column_text(statement, 0), let titre = sqlite3_column_text(statement, 1) { let refString = String(cString: ref) let titreString1 = String(cString: titre) let titreString2 = titreString1.replacingOccurrences(of: "\\n", with: "") let titreString3 = titreString2.replacingOccurrences(of: "`", with: "'") let titreString = titreString3.replacingOccurrences(of: "...", with: "") cantiques.append(["ref": refString, "titre": titreString]) } } } else { print("Error preparing query") } sqlite3_finalize(statement) sqlite3_close(db) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } Merci bien
5
0
1.5k
Mar ’23