简体   繁体   中英

PFFile? is not convertible to 'StringLiteralConvertible' 'AnyObject' is not convertible to 'String'

I just updated:

xcodeVersion 6.3 (6D570)

Swift 1.2 has messed up my word last night and apparently they have made some changes in either Swift or Parse.

I am confused I just don't know how to fix this issue... Need help please. If someone else has experienced the same and has fixed it, please help me.

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 returns optional value, if you sure, that your user is login and have created a PFSession then try this:

var user = PFUser.currentUser()!

let me know, if this doesn't solve the problem.

By trial and error .. this worked for me Parse 1.7.1 and Swift 1.2

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

object?["bax"] as? String object?["abc"] as! PFFile? -> But my image is not showing now ... still trying to solve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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