Stephanie
Stephanie

Reputation: 1

SwiftUI Firebase Profile Picture current code

I have been studying Firebase for a month and understand Auth and Firestore well enough for a beginner. Storage is a bit harder. I just want an Hstack with my users profile pic 😃 and message to be added to a list of messages when written.

EXAMPLE

😃 the message

I don't know how to apply to my UI I guess. Please only kindness in answers, I don't want to be belittled or spoken sharply to. It has taken me 2 years to ask a question on here again because of how cruelly I was treated before making me feel foolish.

I bought a book (because I'm having ZERO luck finding CURRENT examples for this online) that gave me these codes but false starter codes which became confusing. Also can't find Firebase help for 2023 and their current codes.

This is code I have but the View is embarrassing because I was following the book and it stopped so I don't even understand what it left me with. I don't know if showing my code will even help but I know it is requested a lot.

so This is what I have as View Model, and then I added my View after which makes no sense to me because the book just left me there.

class PostViewModel: ObservableObject{
    
    @Published var posts = [Post]()
    
    let storageReference = Storage.storage().reference().child("\.  
    (UUID().uuidString)")
    
    private var databaseReference = Firestore.firestore().collection("Posts")
    
    
    func Task() async{
        await self.addData(description: "", datePublished: Date(), data: Data())
    }
    
    
    func addData(description:String, datePublished:Date, data:Data) async {
        
        do{
            _ = try await storageReference.putData(data, metadata: nil){
                (metadata, error) in
                
                guard let metadata = metadata else{
                    return
                }
                
                self.storageReference.downloadURL {
                    (url, error)  in
                    
                    guard let downloadURL = url else{
                        //
                        return
                    }
                    self.databaseReference.addDocument(data: ["description":  
    description, "datePublished": datePublished,"ImageURL": 
    downloadURL.absoluteString])
                }
            }
                } catch {
                    print(error.localizedDescription)
                
                
            }
            
     
    }
}
 ______________________________________________
 THE VIEW FOLLOWING 🤷‍♀️🤷‍♀️🤷‍♀️🤷‍♀️🤷‍♀️🤷‍♀️
______________________________________________
struct PostView: View {
    @FirestoreQuery(collectionPath:"Posts")
    var posts: [Post]
    @ObservedObject var viewModel = PostViewModel()
    
    @State var tf = ""
    

    
    var body: some View {
        
        
        VStack{
            
            
            List(posts){post in
                
                
                Text(posts.description )
                    .font(.title)
                Text("Published on \(post.datePublished? .formatted() ?? "")")
                    .font(.title)
                
            }
            .frame(minHeight:150, maxHeight: 300)
            
       
             
            
        }
    }
}

Upvotes: 0

Views: 96

Answers (0)

Related Questions