PFFile?不能转换为' StringLiteralConvertible' ' AnyObject'不能转换为' String'

时间:2015-04-10 19:58:11

标签: ios swift parse-platform xcode6 pfobject

我刚刚更新了:

  

xcodeVersion 6.3(6D570)

Swift 1.2昨晚搞砸了我的话,显然他们已经在Swift或Parse中做了一些改变。

我很困惑我只是不知道如何解决这个问题...请帮助。如果其他人经历过同样的事情并修复了它,请帮助我。

import UIKit
import Parse

class ProfileViewController: UIViewController, UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

    // MARK: Variables declaration
    @IBOutlet weak var uploadPhotoBtn: UIButton!
    @IBOutlet weak var profilePhotoImageView: UIImageView!
    @IBOutlet var welcomeMessageLabel: UIView!
    @IBOutlet weak var greetings: UILabel!

    var imagePicker = UIImagePickerController()
    var existingImage : UIImage?
    var user = PFUser.currentUser()




    // The view has loaded this is the function that will be run at first before anything else
    override func viewDidLoad() {
        super.viewDidLoad()

        // MARK: make a circle image
        profilePhotoImageView.layer.cornerRadius = profilePhotoImageView.frame.size.width/2
        profilePhotoImageView.clipsToBounds = true

        //show my status 
        var mood = self.user["status"] as! String //=> 'AnyObject' is not convertible to 'String'

        self.greetings.text? = ( "\(mood)" )

        //get image if existing
        self.user[ "avatar" ] as? PFFile //=> 'PFFile? is not convertible to 'StringLiteralConvertible'

        if let userImageFile = self.user["avatar"] as? PFFile {PFFile? is not convertible to 'StringLiteralConvertible'

            userImageFile.getDataInBackgroundWithBlock({ (imageData:NSData!, error: NSError!) -> Void in

                if error == nil {

                    self.existingImage = UIImage(data: imageData)
                    self.profilePhotoImageView.image = self.existingImage
                }else {

                    let alert = UIAlertView(title: "Oops!", message: "Unable to get your profile photo", delegate: self, cancelButtonTitle: "Ok!")
                    alert.show()

                }
            })
        }

2 个答案:

答案 0 :(得分:2)

PFUser.CurrentUser返回可选值,如果您确定,您的用户已登录并创建了PFSession,请尝试以下操作:

var user = PFUser.currentUser()!

请告诉我,如果这不能解决问题。

答案 1 :(得分:1)

通过反复试验..这对我来说是Parse 1.7.1和Swift 1.2

覆盖func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath,object:PFObject?) - > PFTableViewCell?

对象?[" bax"]为?串 对象?[" abc"]为! PFFile? - >但我的图像现在还没有显示......仍然试图解决它。