首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装cocoapods后,“无法在范围内找到AlbumArt”&将应用程序连接到firebase。Xcode & SwiftUI

安装cocoapods后,“无法在范围内找到AlbumArt”&将应用程序连接到firebase。Xcode & SwiftUI
EN

Stack Overflow用户
提问于 2021-02-17 17:54:05
回答 2查看 947关注 0票数 1

昨天,我安装了cocoapods和我正在为一个学校项目做的音乐播放器应用程序的防火墙依赖项。我总是创建新的分支来尝试它,以防它不起作用。我使用的是最新版本的Xcode和最新版本的firebase与。

我的ContentView中有几个结构,例如SongCell、唱片、歌曲和AlbumArt。

然后,我有了另一个名为PlayerView的快速文件,在这里,我为播放歌曲的播放器设计了视图。在这里,我有一个V堆栈,其中显示文本和AlbumArt。所有这些都没有任何问题,直到我安装了podfile,并将应用程序连接到了firebase。然后,突然之间,我无法构建或运行应用程序,因为'AlbumArt在PlayerView文件中的作用域中找不到‘。

摘要:

  1. I在ContentView

中有一个名为AlbumArt的结构

  1. 这个结构也在PlayerView示例中使用:

AlbumArt(相册:相册,isWithText:假)

  1. 在我安装cocoapods和firebase之前,一切都很好,

  1. 现在在PlayerView

中“无法在范围内找到AlbumArt”

  1. --无论我想从ContentView到PlayerView使用什么结构,我都会得到“在范围内找不到”,所以在使用ContentView内部的结构时,似乎是个问题。

  1. 如何解决这个问题?

提前谢谢。我将发布来自ContentView、PlayerView和下面的podfile的代码。

ContentView中的代码:

代码语言:javascript
复制
import SwiftUI
import Firebase



struct Album : Hashable {
    var id = UUID()
    var name : String
    var image : String
    var songs : [Song]
}

struct Song : Hashable {
    var id = UUID()
    var name : String
    var time : String
    
}

struct ContentView: View {

    @ObservedObject var data : MyData
    @State private var currentAlbum : Album?
    
    
    var body: some View {
        NavigationView{
            ScrollView{
                ScrollView(.horizontal, showsIndicators: false, content: {
                    LazyHStack{
                        ForEach(self.data.albums, id:\.self, content: {
                            album in
                                AlbumArt(album: album, isWithText: true).onTapGesture {
                                    self.currentAlbum = album
                                }
                    })
                    }
                            
                })
                LazyVStack{
                    if self.data.albums.first == nil {
                        EmptyView()
                        
                    }else {
                        ForEach((self.currentAlbum?.songs ?? self.data.albums.first?.songs) ??
                                            [Song(name:"Song 1", time: "3:11"),
                                              Song(name:"Song 2", time: "3:11"),
                                              Song(name:"Song 3", time: "3:11"),
                                              Song(name:"Song 4", time: "3:11"),
                                              Song(name:"Song 5", time: "3:11"),
                                              Song(name:"Song 6", time: "3:11")],
                        id: \.self,
                        content: {
                        song in
                            SongCell(album: currentAlbum ?? self.data.albums.first!, song: song)
                })
                    
                }
                    
                
            }.navigationTitle("Sinemark")
        }
    }
}

struct AlbumArt : View{
    var album : Album
    var isWithText : Bool
    var body: some View {
        ZStack (alignment: .bottom, content: {
        
            Image(album.image)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 170, height: 200, alignment: .center)
            
            if isWithText == true {
            ZStack {
                Blur(style: .dark)
                Text(album.name).foregroundColor(.white)
            }.frame(height: 60, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                
        }
    }).frame(width: 170, height: 200,alignment: .center) .clipped().cornerRadius(20).shadow(radius: 10).padding(20)
            
                
    }
}

struct SongCell : View{
    var album : Album
    var song : Song
    var body: some View{
        NavigationLink(
            destination: PlayerView(album: album, song: song), label: {
                    HStack{
                            ZStack{
                                Circle().frame(width: 50, height: 50, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
                                Circle().frame(width: 20, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).foregroundColor(.white)
                            }
                            Text(song.name).bold()
                            Spacer()
                            Text(song.time)
                        }.padding(20)
            
            }).buttonStyle(PlainButtonStyle())
    }
    
}


}

PlayerView中的代码:

代码语言:javascript
复制
import Foundation
import SwiftUI




struct PlayerView : View {
    var album : Album
    var song : Song
    

    
    @State var isPlaying : Bool = false
    
    var body: some View {
        ZStack {
            Image(album.image).resizable().edgesIgnoringSafeArea(.all)
            Blur(style: .dark).edgesIgnoringSafeArea(.all)
            VStack{
        
                Spacer()
                AlbumArt(album: album, isWithText: false)
                Text(song.name).font(.title).fontWeight(.light).foregroundColor(.white)
                Spacer()
                ZStack {
                    
                    Color.white.cornerRadius(20).shadow(radius: 10)
                    
                    HStack {
                        
                        Button(action: self.previous, label: {
                            Image(systemName: "arrow.left.circle").resizable()
                        }).frame(width: 50, height: 50, alignment: .center).foregroundColor(Color.black.opacity(0.2))
                        
                        Button(action: self.playPause, label: {
                            Image(systemName: isPlaying ? "pause.circle.fill" : "play.circle.fill").resizable()
                        }).frame(width: 70, height: 70, alignment: .center).padding()
                        
                        Button(action: self.next, label: {
                            Image(systemName: "arrow.right.circle").resizable()
                        }).frame(width: 50, height: 50, alignment: .center).foregroundColor(Color.black.opacity(0.2))
                            
                        }
                    
                }.padding().edgesIgnoringSafeArea(.bottom).frame(height: 200, alignment: .center)
                }
            }
        }
        
    func playPause() {
        self.isPlaying.toggle()
        
    }
    
    func next () {
        
    }
    
    func previous () {
        
    }
    
    
}

我的文件:

代码语言:javascript
复制
# Uncomment the next line to define a global platform for your project
  platform :ios, '14.4'

target 'BandApp_MusicPlayer' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for BandApp_MusicPlayer
    pod 'Firebase/Firestore'
    pod 'Firebase/Storage'
    pod 'Firebase/Analytics'
    

  target 'BandApp_MusicPlayerTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'BandApp_MusicPlayerUITests' do
    # Pods for testing
  end

end
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-17 23:04:13

您的AlbumArt结构定义是ContentView结构的内部定义,因此从PlayerView的角度来看,它超出了范围。您也可以对SongCell进行同样的操作,您不必在ContentView结构中定义它。

如果您将该struct定义移动到您的快速文件的根级别,它将编译。

代码语言:javascript
复制
struct ContentView: View {
  // all your ContentView stuff
}

struct AlbumArt : View {
  // this definition here
}
票数 1
EN

Stack Overflow用户

发布于 2021-02-17 21:54:21

我想我看到了问题--您的AlbumArt类中有占位符代码:

/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/

它出现在代码的这一部分中:

代码语言:javascript
复制
if isWithText == true {
    ZStack {
        Blur(style: .dark)
        Text(album.name).foregroundColor(.white)
    }.frame(height: 60, alignment: .center) <--- RIGHT HERE
}

如果这能解决问题请告诉我!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66247408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档