2017-05-03 4 views
-1

Dies ist der Code, den ich für meine Profilseite erstellt habe, aber er hat einige Fehler, die ich anpassen möchte.Profilseite swift 3 Fehler

enter image description here

import UIKit 
import FirebaseStorage 
import FirebaseDatabase 
import FirebaseAuth 
import Firebase 


class ProfileClass: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 


    @IBOutlet weak var userImagePicker: RoundButton! 
    @IBOutlet weak var ProfilePicture: RoundImage! 
    @IBOutlet weak var usernameField: UITextField! 
    @IBOutlet weak var imageLoader: UIActivityIndicatorView! 


    var loggedInUser = AnyObject?() 
    var databaseRef = FIRDatabase.database().reference() 
    var storageRef = FIRStorage.storage().reference() 
    var imagePicker = UIImagePickerController() 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.loggedInUser = FIRAuth.auth()?.currentUser 

     self.databaseRef.child("user_profile").child(self.loggedInUser!.uid).observeSingleEvent(of: FIRDataEventType(.Value) { (snapshot:FIRDataSnapshot) in 


      if(snapshot.value!["usernameField"] !== nil) { 

      self.usernameField.text = snapshot.value!["usernameField"] as? String 

      } 
      if(snapshot.value!["profile_pic"] !== nil) { 

      let databaseProfilePic = snapshot.value!["profile_pic"] 
      as! String 
       let data = NSData(contentsOfURL: NSURL(string: databaseProfilePic)!) 

       self.setProfilePicture(self.ProfilePicture,imageToSet:UIImage(data:data!)!) 

      } 
     } 
    } 


    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 



    @IBAction func logoutTapped(_ sender: Any) { 
     let firebaseAuth = FIRAuth.auth() 
     do { 
      try firebaseAuth?.signOut() 
     } catch let signOutError as NSError { 
      print ("Error signing out: %@", signOutError) 
     } 
    self.performSegue(withIdentifier: "goToLogin", sender: self) 
    } 


    @IBAction func TapProfileButton(_ sender: RoundButton) { 

     let myActionShett = UIAlertController(title:"Profile Picture",message:"Select",preferredStyle: UIAlertControllerStyle.actionSheet) 

     let viewPicture = UIAlertAction(title: "View Picture", style: UIAlertActionStyle.default) { (action) in 

      let imageView = sender.view as! RoundImage 
      let newImageView = RoundImage(image: imageView.image) 

      newImageView.frame = self.view.frame 

      newImageView.backgroundColor = UIColor.blackColor() 
      newImageView.contentMode = .scaleAspectFit 
      newImageView.userInteractionEnabled = true 

      let tap = UITapGestureRecognizer(target:self,action:#selector(self.dismissFullScreenImage)) 

      newImageView.addGestureRecognizer(tap) 
      self.view.addSubview(newImageView) 

     } 

     let photoGallery = UIAlertAction(title: "Photos", style: UIAlertActionStyle.default) { (action) in 

      if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum) 
      { 
      self.imagePicker.delegate = self 
      self.imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum 
      self.imagePicker.allowsEditing = true 
      self.present(self.imagePicker, animated: true, completion: nil) 

      } 

     } 

     let camera = UIAlertAction(title: "Camera", style: UIAlertActionStyle.default) 
     { (action) in 

     if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) 

     { 

     self.imagePicker.delegate = self 
     self.imagePicker.sourceType = UIImagePickerControllerSourceType.camera 
     self.imagePicker.allowsEditing = true 
     self.present(self.imagePicker, animated: true, completion: nil) 

      } 

     } 

    myActionShett.addAction(viewPicture) 
    myActionShett.addAction(photoGallery) 
    myActionShett.addAction(camera) 
    myActionShett.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)) 

    self.present(myActionShett, animated: true, completion: nil) 

    } 







    func dismissFullScreenImage(sender:UITapGestureRecognizer) 
    { 
    sender.view?.removeFromSuperview() 
    } 



    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 

     self.imageLoader.stopAnimating() 
     setProfilePicture(self.ProfilePicture,imageToSet: image) 

     if let imageData: NSData = UIImagePNGRepresentation(self.ProfilePicture, image!)! 
     { 
     let profilePicStorageRef = storageRef.child("user_profiles/\(self.loggedInUser!.uid)/profile_pic") 

      let uploadTask = profilePicStorageRef.putData(imageData, metadata: nil) 
      {metadata,error in 

      if(error == nil) 
      { 
       let downloadUrl = metadata!.downloadUrl() 
       self.databaseRef.child("user_profile").child(self.loggedInUser!.uid).child("profile_pic").setValue(downloadUrl!.absoluteString) 
      } 
      else 
      { 
      print(error?.localizedDescription) 

      } 
       self.imageLoader.stopAnimating() 

      } 
      } 
     self.dismiss(animated: true, completion: nil) 

    } 
} 
+0

die Fehlerliste ist in dem Bild, dass ich in der Nähe "jemand kann mir helfen?" – user7931810

+1

Sie können keine Instanz von AnyObject erstellen und Sie können sicherlich keine Instanz von AnyObject erstellen? – Paulw11

+0

so? was muss ich erschaffen? @ Paulw11 – user7931810

Antwort

2

Sie haben die richtige Art zu geben. Sie können Objekt vom Typ AnyObject nicht initialisieren. und natürlich ohne AnyObject zu verwenden ?.