我目前有一个JSQMessagesViewController
,但我遇到了在Parse.com中存储我的JSQMessages
的问题,因为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_)
}
}
我在ChatView
中的实施是JSQMessagesViewController
:
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