Post

Replies

Boosts

Views

Activity

ForEach error with array of videos
I'm stuck on these errors "Cannot declare entity named '$reel'; the '$' prefix is reserved for implicitly-synthesized declarations" "Generic struct 'ForEach' requires that 'Binding<[Reel]>' conform to 'RandomAccessCollection'" Both errors are on this line of code ForEach($reels) { $reel in           ReelsPlayer(reel: $reel) } I have a TabView {} and am trying to make each page a new video similar to tik tok or vine. It works when I pass in dummy data but when I pass from my array of videos I get those errors. Here's the rest of the code The View: import SwiftUI import AVKit struct ReelsView: View {       @State var currentReel = ""         // extracting AVPlayer from media file   @State var reels: [Reel] = MediaFileJSON.map { item -> Reel in           let url = Bundle.main.path(forResource: item.url, ofType: "MP4") ?? ""           let player = AVPlayer(url: URL(fileURLWithPath: url))           return Reel(player: player, mediaFile: item)   }       var body: some View {           // setting width and height for rotated view     GeometryReader { proxy in               let size = proxy.size               // vertical page tab view       TabView(selection: $currentReel) {                   ForEach($reels) { $reel in // ERRORS HERE           ReelsPlayer(reel: $reel)           // setting width           .frame(width: size.width)           .padding()           // rotate content           .rotationEffect(.init(degrees: -90))         }       }       // Rotate View       .rotationEffect(.init(degrees: 90))       // setting height as width       .frame(width: size.height)       .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))       // setting max width       .frame(width: size.width)             }   } } struct ReelsView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } struct ReelsPlayer: View, Identifiable {   var id: ObjectIdentifier           @Binding var reel: Reel       var body: some View {           ZStack {                     }   } } MediaFile struct: struct MediaFile: Identifiable {   var id = UUID().uuidString   var url: String   var title: String   var isExpanded: Bool = false } var MediaFileJSON = [       MediaFile(url: "Reel1", title: "Apple AirTag......."),   MediaFile(url: "Reel2", title: "this is the second."),   MediaFile(url: "Reel3", title: "the third"),   MediaFile(url: "Reel4", title: "wooooooooooooo ya"),   MediaFile(url: "Reel5", title: "ay ayayayayay ayay lsdfk sl"),   MediaFile(url: "Reel6", title: "this is the last one....."),     ] Reel struct: struct Reel: Identifiable {       var id: String = UUID().uuidString   var player: AVPlayer?   var mediaFile: MediaFile }
3
0
1.7k
Jul ’21