繁体   English   中英

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

[英]PFFile? is not convertible to 'StringLiteralConvertible' 'AnyObject' is not convertible to 'String'

我刚刚更新:

xcode版本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()

                }
            })
        }

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

var user = PFUser.currentUser()!

让我知道,如果这不能解决问题。

通过反复试验..这为我工作解析1.7.1和Swift 1.2

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

对象?[“ bax”]如? 字符串对象?[“ abc”]如! PFFile? ->但是我的图像现在没有显示...仍在尝试解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM