所以当我只有myImageView1时它很好但为什么当我在旁边添加myImageView2并用逗号分隔时它会给我一个错误。错误发生在uploadData部分。我该如何解决这个问题?
@IBAction func upload(_ sender: Any) {
let storageRef = Storage.storage().reference().child("images/\(NSUUID().uuidString)/image.png")
if let uploadData = UIImagePNGRepresentation(self.myImageView1.image!){
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if error != nil {
print("error")
return
}
else {
let downloadURL = metadata?.downloadURL()?.absoluteString
self.ref?.child("Posts").childByAutoId().setValue(["Download URL": (downloadURL), "Download URL 2": (downloadURL2)])
}
答案 0 :(得分:1)
来自UIImagePNGRepresentation
的声明:
func UIImagePNGRepresentation(_ image: UIImage) -> Data?
此函数只接受一个参数。您需要单独获取数据并找到将它们合并为一个Data
对象的方法。