Cannot store NSURL and __SwiftValue (Can only store objects of type NSNumber, NSString, NSDictionary) errors the bottom two blocks of code?

妖精的绣舞 提交于 2021-01-29 15:52:33

问题


So for the second last block(newImageRef.putData), I can define downloadURL as String?, but then I get __SwiftValue error at the last block (newImageRef.putData1).

And even defining downloadURL as a string seems dangerous because looking at the documentation https://firebase.google.com/docs/reference/swift/firebasestorage/api/reference/Classes/StorageMetadata it seems to be used as a URL integral to the function.

Other than these terminal error, there is a yellow error that warns Value 'downloadURL' was defined but never used; consider replacing with boolean test

 func save() {




        let uid = Auth.auth().currentUser!.uid
        let newPostRef = Database.database().reference().child("people").child(uid).child("PhotoPosts")
        let newPostRef1 = Database.database().reference().child("people").child(uid).child("PhotoPosts1")


        let newPostKey = newPostRef.key



        if let imageData = image.jpegData(compressionQuality: 0.001){

            let imageStorageRef = Storage.storage().reference().child("images").child(uid)


            let newImageRef = imageStorageRef.child(newPostRef.key!)
            let newImageRef1 = imageStorageRef.child(newPostRef1.key!)



            newImageRef.putData(imageData).observe(.success, handler: {(snapshot) in
              newImageRef.downloadURL { (url, error) in
                guard let downloadURL = url else {
                  return
                }
                newPostRef.setValue(url)
              }
            })

            newImageRef1.putData(imageData).observe(.success, handler: {(snapshot) in
                                                    newImageRef1.downloadURL { (url, error) in
                                                      guard let downloadURL = url else {
                                                        return
                                                      }
                                                      let keyToPost = Database.database().reference().child("people").child(uid).childByAutoId().key ?? "I am a default value"
                                                      let f1: [String: Any] = [(keyToPost) : newImageRef1.downloadURL as Any]

                                                      newPostRef1.updateChildValues(f1)
                                                    }
                                                  })

Below is what I had it at before but changed due to pod updates

                newImageRef.putData(imageData).observe(.success, handler: {(snapshot) in
                self.imageDownloadURL = snapshot.metadata?.downloadURL()?.absoluteString
                newPostRef.setValue(self.imageDownloadURL as Any)


            })

来源:https://stackoverflow.com/questions/61594804/cannot-store-nsurl-and-swiftvalue-can-only-store-objects-of-type-nsnumber-ns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!