为 PFUser 分配一个 PFObject Swift

Assigning PFUser with A PFObject Swift

如何将 PFUser 添加到 PFObject,现在是我的代码:

var gameScore = PFObject(className: "SiteLog-\(jobName.text)")
gameScore["TypeOfWorks"] = "\(typeOfWorks.text)"
gameScore["DateAndTime"] = "\(formattedDate)"
gameScore.saveInBackgroundWithBlock {
        (success: Bool, error: NSError?) -> Void in
        if (success) {
            // The object has been saved.
            println("sucessfully sent to parse!")
        } else {
            // There was a problem, check error.description
            println("Error Sending to Parse = \(error)")
        }

那么我如何才能为它分配一个用户,该用户已经登录,那么我如何才能将这个 PFObject 分配给当前登录的用户!

我正在使用 iOS Swift - Xcode 6.3.1

谢谢, 乔治·巴洛

在 Objective-C 中,您可以通过调用 [PFUser currentUser] 来引用已登录的用户,这应该将 Swift 转换为 PFUser.currentUser()。假设您有一个名为 user 的 gameScore 列,您可以在保存 gameScore 之前添加这行代码:

    if let user = PFUser.currentUser(), username = user.username {
        user["column-name-in-parse-data"] = username
    }