urban-health-labs / CombineFirebase

Combine wrapper on Google's iOS Firebase library.
MIT License
225 stars 44 forks source link

'Generic parameter 'Value' could not be inferred' #1

Closed ysakurada closed 4 years ago

ysakurada commented 4 years ago

Thank for uploading this repository. I used sample code this and get this error.

'Generic parameter 'Value' could not be inferred'

var cancelBag = Set<AnyCancellable>()
let reference = Storage.storage()
    .reference(forURL: "\(your_firebase_storage_bucket)/images/space.jpg")

let fileURL: URL // Upload file
let uploadTask = reference.putFile(from: fileURL)

// Listen for state changes
uploadTask.publisher(.progress)
    .sink(receiveCompletion: { completion in
       switch completion {
       case .finished: print("๐Ÿ finished")
       case .failure(let error): // Uh-oh, an error occurred! 
       }
   }) { snapshot in
      // Upload reported progress
      let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
      / Double(snapshot.progress!.totalUnitCount)
   }
   .store(in: &cancelBag)

Did you get this kind of error? And This code need 'break' after 'case .failure(let error)'.๐Ÿ‘

kshivang commented 4 years ago

Hey ysakurada,

Thank you for pointing that out. There were two things that was wrong, Sample should be:

   var cancelBag = Set<AnyCancellable>()

    func uplodTask() {
        let someBucket = "some_bucket"
        let reference = Storage.storage()
            .reference(forURL: "\(someBucket)/images/space.jpg")

        if let fileURL = URL(string:"some") {
            let uploadTask = reference.putFile(from: fileURL)
            uploadTask.publisher(.progress)
                .sink(receiveCompletion: { _ in
                    // error will never call here
                    print("๐Ÿ finished")
                }) { (snapshot) in
                    if let error = snapshot.error {
                            print("error: \(error)")
                        }
                    let percentComplete = 100.0 * Double(snapshot.progress?.completedUnitCount ?? 0) / Double(snapshot.progress?.totalUnitCount ?? 1)
            }.store(in: &cancelBag)
        }
    }

Also method publisher(_ status:) was not public, source of library. I updated that in version 0.2.4. Please update using: pod update

ysakurada commented 4 years ago

Thank you for fixing bug๐Ÿ‘ And Giving new sample code๐Ÿ‘

This repository make helpful for everyone๐Ÿ‘๐Ÿ’™Like!