1

我目前有一个JSQMessagesViewController,但我遇到了将我的存储JSQMessages在 Parse.com 中的问题,因为 Parse.com 不允许这种类型的对象。我一直在尝试研究创建子类PFObject同时符合 的类的方法,JSQMessageData以便我可以创建类型的消息,PFObject从而能够存储在 Parse.com 中。

下面是我的Messages课。在我的JSQMessagesViewController我通常会打电话

    var newMessage = JSQMessage(senderId: "user", displayName: "user", text: "testing chat")

但是现在我将如何在我的Messages课堂上做到这一点?

import Foundation
import UIKit
import Parse

class Message: PFObject, PFSubclassing, JSQMessageData {
    var senderId_ : String!
    var senderDisplayName_ : String!
    var date_ : NSDate
    var isMediaMessage_ : Bool
    var hash_ : Int = 0
    var text_ : String


    override class func initialize() {
        var onceToken : dispatch_once_t = 0;
        dispatch_once(&onceToken) {
            self.registerSubclass()
        }
    }

    class func parseClassName() -> String {
            return "Messages"
        }

    convenience init(senderId: String?, text: String?) {
        self.init(senderId: senderId!, senderDisplayName: senderId, isMediaMessage: false, hash: 0, text: text!)
    }

    init(senderId: String, senderDisplayName: String?, isMediaMessage: Bool, hash: Int, text: String) {

            self.senderId_ = senderId
            self.senderDisplayName_ = senderDisplayName
            self.date_ = NSDate()
            self.isMediaMessage_ = isMediaMessage
            self.hash_ = hash
            self.text_ = text
            super.init()

        }

    func senderId() -> String? {
            return senderId_;
        }

    func senderDisplayName() -> String? {
            return senderDisplayName_;
        }

    func date() -> NSDate? {
            return date_;
        }

    func isMediaMessage() -> Bool {
                return isMediaMessage_;
        }

    func hash() -> UInt? {
        return UInt(hash_);
    }


    func text() -> String! {
        return text_;
    }

    func messageHash() -> UInt {
        return UInt(hash_)
    }
}    

我的实现ChatViewJSQMessagesViewController

    override func viewDidLoad(){
        super.viewDidLoad()
        var myObject = PFObject(className: "messages")
        var myMessage = Message(senderId: "User", text: "Some text")
        var messageArray:NSMutableArray = [myMessage]
        myObject["myArray"] = messageArray
        myObject.save()
   }

当前接收错误

fatal error: use of unimplemented initializer 'init()' for class Message
4

0 回答 0