我刚刚更新:
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()!
让我知道,如果这不能解决问题。
关于ios - PFFile?不可转换为'StringLiteralConvertible''AnyObject'不可转换为'String',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29569732/