Home IOS Development ios – How you can add a publish

ios – How you can add a publish

0
ios – How you can add a publish

[ad_1]

I’m making an attempt to add a publish with simply textwords with out photos hooked up I want the textual content to be a separate textual content however my code solely uploads the publish that has a picture hooked up to it and the publish with simply phrases do not present up in firebase

How do I repair this code to permit my consumer add their publish with out photos to firebase

That is the uploadPostViewModel I’ve the textual content as a string however but the info isn’t being uploaded as if it not listed however the picture is what am I lacking from this code that is not permitting my textual content information to be uploaded to firebase

class UploadPostViewModel: ObservableObject {
    @Printed var didUploadPost = false
    @Printed var error: Error?
    @Printed var profileImage: Picture?
    @Printed var caption = ""
    @Printed var textual content = ""
    @Printed var selectedImage: PhotosPickerItem? {
        didSet { Process { await loadImage(fromItem: selectedImage) } }
    }
    
    personal var uiImage: UIImage?
    
    func uploadPost() async throws {
        guard let uid = Auth.auth().currentUser?.uid else { return }
        guard let picture = uiImage else { return }
        
        do {
            guard let picture = strive await ImageUploader.uploadImage(picture: picture, kind: .publish) else { return }
            let publish = Put up(ownerUid: uid,textual content: textual content, caption: caption, likes: 0, replyCount: 67, picture: picture, timestamp: Timestamp())

            
            strive await PostService.uploadPost(publish)
            self.didUploadPost = true
        } catch {
            print("DEBUG: Did not add picture with error (error.localizedDescription)")
            self.error = error
        }
    }
    
    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)
    }
}
 @State var captionText = ""
       
       @StateObject var viewModel = UploadPostViewModel()
       @Surroundings(.dismiss) var dismiss
      
       @Binding var tabIndex: Int
       
       personal var consumer: Userss? {
           return ThirdUserService.shared.currentUser
       }
       var physique: some View {
           NavigationStack {
               VStack {
                   HStack(alignment: .high) {
                       RectangularImageSize(consumer: consumer, measurement: .small)
                       
                       VStack(alignment: .main, spacing: 4) {
                           Textual content(consumer?.username ?? "")
                               .fontWeight(.semibold)
                           
                           TextField("Sort One thing", textual content: $viewModel.textual content, axis: .vertical)
                       }
                       .font(.footnote)
                       
                       Spacer()
                       
                       if !viewModel.textual content.isEmpty {
                           Button {
                               viewModel.textual content = ""
                           } label: {
                               Picture(systemName: "xmark")
                                   .resizable()
                                   .body(width: 12, top: 12)
                                   .foregroundColor(.grey)
                           }
                       }
                   }
                   
                   Spacer()
               }
               .padding()
               .toolbar {
                   ToolbarItem(placement: .navigationBarLeading) {
                       Button("Cancel") {
                           dismiss()
                       }
                       .font(.subheadline)
                       .foregroundStyle(Shade.black)
                   }
                   
                   ToolbarItem(placement: .navigationBarTrailing) {
                       Button("Put up") {
                           Process {
                               strive await viewModel.uploadPost()
                               dismiss()
                           }
                       }
                       .opacity(viewModel.textual content.isEmpty ? 0.5 : 1.0)
                       .disabled(viewModel.textual content.isEmpty)
                       .font(.subheadline)
                       .fontWeight(.semibold)
                       .foregroundStyle(Shade.inexperienced)
                   }
               }
               .onDisappear { tabIndex = 0 }
               
           }
       }
   }

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here