Post

Replies

Boosts

Views

Activity

Problem with testing on a physical device
Hello, I am having the following issue: I am using the packages DSWaveformImage and DSWaveformImageViews if that matters. My code's goal is to generate waveform images from files embedded in the application. That works great on a simulator device, but when I run the code on a physical device (iPhone 15 Pro, iOS 18.2), I get this error (shown in the attached screenshot below):
1
0
102
3d
Bug fix
Hello, I have these two errors in this particular block of code: Capture of 'self' with non-sendable type 'MusicPlayer?' in a @Sendable closure and Capture of 'localUpdateProgress' with non-sendable type '(Double, Double) -> Void' in a @Sendable closure ` @MainActor func startProgressTimer(updateProgress: @escaping (Double, Double) -> Void) { timer?.invalidate() // Stop any existing timer let localUpdateProgress = updateProgress timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in guard let self = self, let audioPlayer = self.audioPlayer, let currentItem = audioPlayer.currentItem else { print("currentItem is nil or audioPlayer is unavailable") return } let currentTime = currentItem.currentTime().seconds let duration = currentItem.duration.seconds localUpdateProgress(currentTime, duration) } }` I've tried nearly every solution and can't think of one that works. Any help is greatly appreciated :)
1
0
218
Nov ’24
Problem with audio files in Swift
Hi guys, I've been this app for quite a while and I wanted to add audio to it but I've encountered a strange bug. Whenever I try to play the audio from the testing device, it prints out that the audio file cannot be found. I've checked multiple times the names and the code and I get no errors there whatsoever. I have no idea what might be causing this. Here's a part of the code: `import SwiftUI import AVFoundation struct Card: Identifiable { let id = UUID() let heading: String let description: String let imageName: String let detailDescription: String let sonification: String } struct ExplorepageUI: View { @State private var selectedCard: Card? @State private var showMore = false @State private var currentIndex = 0 @State private var currentCards: [Card] = [] let galaxies = [ Card(heading: "The Mice Galaxies", description: "They’re located about 300 million light-years away in the constellation Coma Berenices.", imageName: "TheMiceGalaxiesHubble", detailDescription:""" Their name refers to the long tails produced by tidal action, the relative difference between gravitational pulls on the near and far parts of each galaxy, known here as a galactic tide. It is a possibility that both galaxies, which are members of the Coma Cluster, have experienced collision, and will continue colliding until they coalesce. The colors of the galaxies are peculiar. In NGC 4676A a core with some dark markings is surrounded by a bluish white remnant of spiral arms. The tail is unusual, starting out blue and terminating in a more yellowish color, despite the fact that the beginning of each arm in virtually every spiral galaxy starts yellow and terminates in a bluish color. NGC 4676B has a yellowish core and two arcs; arm remnants underneath are bluish as well. The galaxies were photographed in 2002 by the Hubble Space Telescope. In the background of the Mice Galaxies, there are over 3000 galaxies, at distances up to 13 billion light-years. """, sonification: "SonificationoftheMiceGalaxies"), `class MusicPlayer: ObservableObject { private var audioPlayer: AVPlayer? func playSound(named sonificationFileName: String){ if let url = Bundle.main.url(forResource: sonificationFileName, withExtension: "mp3"){ print("✅ Found audio file at: \(url)") audioPlayer = try? AVPlayer(url: url) audioPlayer?.play() print("🎵 Audio should now be playing!") } else { print("❌ Audio file not found: \(sonificationFileName).mp3") } } func pause(){ audioPlayer?.pause() } }
1
0
215
Nov ’24
Problem with ScrollView
Hi guys, I have a really odd problem. Whenever I try to add a vertical ScrollView, VStack or a LazyVStack to this code everything disappears. Anyone have an idea why this is happening and how to fix it? No errors show up in my code. GeometryReader{ geometry in VStack(alignment: .center, spacing: 100){ ScrollView(.horizontal, showsIndicators: false){ HStack(spacing: 250){ CardView1( showOnlyImage: false, imagename1: "TheMiceGalaxiesHubble", heading1: "The Mice Galaxies", description1: "Located in the constellation Coma Berenices." ) .scaleEffect(getScale(proxy: geometry)) .animation(.easeOut(duration: 0.3), value: getScale(proxy: geometry)) CardView1( showOnlyImage: false, imagename1: "TheMiceGalaxiesHubble", heading1: "The Mice Galaxies", description1: "Located in the constellation Coma Berenices." ) .scaleEffect(getScale(proxy: geometry)) .animation(.easeOut(duration: 0.3), value: getScale(proxy: geometry)) } } .frame(height: -200) ScrollView(.horizontal, showsIndicators: false){ HStack(spacing: 250){ CardView1( showOnlyImage: false, imagename1: "TheMiceGalaxiesHubble", heading1: "The Mice Galaxies", description1: "Located in the constellation Coma Berenices." ) .scaleEffect(getScale(proxy: geometry)) .animation(.easeOut(duration: 0.3), value: getScale(proxy: geometry)) } } } } } .contentMargins(50, for: .scrollContent) .scrollTargetBehavior(.viewAligned) .scrollTargetLayout() .padding(.horizontal, 10) .padding(.top, -35) .padding(.bottom, 50) } } } } }
0
0
162
Oct ’24
Closure containing a declaration cannot be used with result builder 'ViewBuilder'
I'm new to Swift and I got this error today. I have another SwiftUI page with the same code but the error doesn't appear there. struct CardView: View { var location: String var description: String var imageName: String var body: some View { VStack{ Image(imageName) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 300, height: 200) // Set a fixed height for each card .background(Color.black.opacity(0.7)) VStack(alignment: .leading) { Spacer() Text(location) .padding(15) .font(.headline) .fontWeight(.bold) .frame(width:300, alignment: .init(horizontal: .leading, vertical: .center)) .foregroundColor(.black) .bold() .background(Color.white) .clipShape(RoundedCorner(radius: 10, corners: [.topLeft, .topRight])) .padding([.leading, .trailing], -14) .padding(.bottom, 10) .offset(y: -213) .offset(x: 28) Text(description) .font(.body) .foregroundColor(.black) .frame(width:300, alignment: .init(horizontal: .leading, vertical: .center)) .background(Color.white) .clipShape(RoundedCorner(radius: 10, corners: [.bottomLeft, .bottomRight])) .padding([.leading, .trailing], 14) .padding(.bottom, 10) .multilineTextAlignment(.leading) .lineLimit(nil) .offset(y: 2) } .padding() .frame(width: 200) .fixedSize() } .frame(height: 350) // Ensure each card has a fixed height .background(Color.white) .cornerRadius(10) .shadow(radius: 5) .padding([.leading, .trailing], 5) // Add padding to the sides for spacing } } } }
1
0
143
Oct ’24