2017-10-28 31 views
-1

午後皆さん、私はfirebaseに画像をアップロードしようとしています。セルに戻って表示しようとしています。画像を除いてすべてのコンテンツが動作しています(私は、 。Swift 4イメージをFirebaseにアップロード

//[Save Image] 
    // Create data in the server 
    let data = UIImageJPEGRepresentation(self.addedImage.image!, 0.5) 
    let metadata = StorageMetadata() 
    metadata.contentType = "image/jpeg" 

    let postId = "\(Auth.auth().currentUser!.uid)\(NSUUID().uuidString)" 
    // Create a reference to the file you want to upload 
    let imagePath = "postImages\(postId)/postPic.jpg" 

    storageRef.child(imagePath).putData(data!, metadata: metadata) { (metadata, error) in 
     if error == nil { 
      let postRef = self.databaseRef.child("posts").childByAutoId() 
      let post = Posts(postImageStringUrl: String (describing: metadata!.downloadURL()), content: descriptionTextView.text, postId: postId) 
      postRef.setValue(post.toAnyObject()) 
     }else{ 
      print(error.debugDescription) 
     } 
    } 
    //[Save Image] 

Here is the error I am getting

は '(文字列:文字列、コンテンツ::文字列!, postId postImageStringUrl)' タイプの引数リストに型 '記事' の初期化子を呼び出すことはできません。ここに私のpostViewControllerがあります

import Foundation 
import Firebase 
import FirebaseDatabase 
import FirebaseStorage

struct Posts {

var postImageStringUrl: String! var department: String! var content: String! var username: String! var postId: String! var ref: DatabaseReference? var key: String! init(postImageStringUrl: String, department: String, content: String, username: String,postId: String, key: String = ""){ self.postImageStringUrl = postImageStringUrl self.department = department self.content = content self.username = username self.postId = postId self.key = key self.ref = Database.database().reference() } init(snapshot: DataSnapshot){ let snapshotValue = snapshot.value as! NSMutableDictionary self.postImageStringUrl = snapshotValue["postImageStringUrl"] as! String self.department = snapshotValue["department"] as! String self.content = snapshotValue["content"] as! String self.username = snapshotValue["username"] as! String self.postId = snapshotValue["postId"] as! String self.key = snapshot.key self.ref = snapshot.ref } func toAnyObject() -> [String: AnyObject] { return ["postImageStringUrl": postImageStringUrl as AnyObject, "department": department as AnyObject,"content": content as AnyObject,"username": username as AnyObject, "postId": postId as AnyObject] }

}

すべてのヘルプは大歓迎されます

... Tyが

あなたの投稿はinitの

答えて

0

init(
    postImageStringUrl: String, 
    department: String, 
    content: String, 
    username: String, 
    postId: String, 
    key: String = "") 

であり、あなただけで基本的に

let post = Posts(
      postImageStringUrl: String (describing: metadata!.downloadURL()), 
      content: descriptionTextView.text, 
      postId: postId) 

で初期化しようとしている表示されます初期化でいくつかのパラメータが欠落しています。部門、ユーザー名

+0

あなたの右そうです!ありがとうございました...私は部門、コンテンツ&ユーザー名を使用しないようにしていましたが、私はそこにいなければならなかったことを認識しませんでした –

+0

@RubenFranco Excellent!お役に立てて嬉しいです。他人を助けることができるように答えを受け入れてください! – Jay

+0

もう一度感謝しました.. –

関連する問題