London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
0 C
New York
Monday, February 3, 2025

ios – add a put up


I’m making an attempt to add a picture to firebase however I’m receiving a error in my feed cell on this line

KFImage(URL(string: put up.picture!))

Thread 1: Deadly error: Unexpectedly discovered nil whereas unwrapping an Optionally available worth

Why am I receiving this error when I attempt to add my consumer picture and the way do I repair this error to add the put up to firebase

import SwiftUI
import Kingfisher
struct FeedCell: View {
    @ObservedObject var viewModel: FeedCellViewModel
    
    var didLike: Bool { return viewModel.put up.didLike ?? false }
    
    init(put up: Publish) {
        self.viewModel = FeedCellViewModel(put up: put up)
    }
    
    personal var consumer: Userss? {
        return viewModel.put up.consumer
    }
    
    personal var put up: Publish {
        return viewModel.put up
    }
    
    var physique: some View {
        VStack(alignment: .main) {
   
            
          
            KFImage(URL(string: put up.picture!))
                .resizable()
                .scaledToFill()
                .body(width: UIScreen.most important.bounds.width, peak: 400)
                .clipped()
                .contentShape(Rectangle())

Publish


import FirebaseFirestoreSwift
import Firebase

struct Publish: Identifiable, Hashable, Codable {
    @DocumentID var id: String?
    let ownerUid: String
    let textual content: String
    let caption: String
    var likes: Int
    var replyCount: Int
    let picture: String?
    let timestamp: Timestamp
    
    var consumer: Userss?
    
    var didLike: Bool? = false
}

UploadPostViewModel

class UploadPostViewModel: ObservableObject {
    @Revealed var didUploadPost = false
    @Revealed var error: Error?
    @Revealed var profileImage: Picture?
    @Revealed var textual content = ""
    @Revealed var selectedImage: PhotosPickerItem? {
        didSet { Job { await loadImage(fromItem: selectedImage) } }
    }
    
    personal var uiImage: UIImage?
    
    func uploadPost(caption: String) async throws {
      guard let uid = Auth.auth().currentUser?.uid else { return }
      var imageUrl: String? = nil
      if let picture = uiImage {
         imageUrl = strive await ImageUploader.uploadImage(picture: picture , kind: .put up)
      }
               
      let put up = Publish(
        ownerUid: uid,
        textual content: textual content, caption: caption,
        likes: 0,
        replyCount: 23,
        picture: imageUrl,
        timestamp: Timestamp()
      )
                    
      strive await PostService.uploadPost(put up)
            self.didUploadPost = true
           
        }
        
        
        func loadImage(fromItem merchandise: PhotosPickerItem?) async {
            guard let merchandise = merchandise else { return }
            
            guard let information = strive? await merchandise.loadTransferable(kind: Knowledge.self) else { return }
            guard let uiImage = UIImage(information: information) else { return }
            self.uiImage = uiImage
            self.profileImage = Picture(uiImage: uiImage)
        }
    }

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com