嗨我想通过ParseLiveQuery获取我的对象ParseLiveQuery无法访问指针对象
我认为ParseLiveQuery不支持指针对象。
这是我的代码片段。
Post.swift
import Foundation
import Parse
class Post: PFObject, PFSubclassing {
@NSManaged var postBy: PFUser?
@NSManaged var postText: String?
@NSManaged var postImg: PFFile?
static func parseClassName() -> String {
return "Post"
}
override class func query() -> PFQuery<PFObject>? {
//1
let query = PFQuery(className: Post.parseClassName())
query.whereKeyExists("objectId")
//2
query.includeKeys(["postBy"])
//3
query.order(byDescending: "createdAt")
return query
}
}
extension Post: FeedCellSupport {
var username:String?{
return postBy?["username"] as? String
}
var userImg:PFFile?{
return postBy?["profileImg"] as? PFFile
}
FeedVC.swif
let liveQueryClient = ParseLiveQuery.Client()
protocol FeedCellSupport {
var username:String?{ get }
var userImg:PFFile?{ get }
var postText: String? { get }
}
class FeedVC: UITableViewController, ShopDetailDelegate {
private var subscription: Subscription<Post>!
//Add friends and me
var postLiveQuery: PFQuery<Post> {
return (Post.query()?
.whereKeyExists("objectId")
.includeKeys(["postBy", "commentBy", "commentBy.commentBy"])
.order(byAscending: "createdAt")) as! PFQuery<Post>
}
var results = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
subscription = liveQueryClient.subscribe(postLiveQuery).handleSubscribe { [weak self] (_) in
// Fetch the objects on subscription to not miss any
self?.fetchObjects()
}.handleEvent { [weak self] (_, event) in
self?.handleEvent(event: event)
}
}
我有2个问题。
1. ParseLiveQuery返回的PFObject类似于REST结果。
当我第一次获取对象它工作正常。
我的意思是我可以通过findObjectBackground获取用户名和userImg数据。
<Post: 0x6180000b43a0, objectId: w5qcfMCByF, localId: (null)> {
likeCount = 0;
postBy = "<PFUser: 0x6180000f4600, objectId: rgG7XfAYWj, localId: (null)>";
postImg = "<PFFile: 0x618000246ba0>";
postText = nice2MeetYous121;
sell = 0;
}
在收到更新的事件后,我得到了不同的样式PFObject。
<Post: 0x6100000b3020, objectId: w5qcfMCByF, localId: (null)> {
"__type" = Object;
className = Post;
createdAt = "2016-11-19T12:37:30.896Z";
likeCount = 0;
postBy = {
"__type" = Pointer;
className = "_User";
objectId = rgG7XfAYWj;
};
postImg = {
"__type" = File;
name = "92aa66bfdcf5f70d1d277556bbd9d7ca_post.jpg";
url = "https://parsefiles.back4app.com/PlY72cbRxsOIXQ1qbJjaQtudZQU9HA8U2RIg2oE1/92aa66bfdcf5f70d1d277556bbd9d7ca_post.jpg";
};
postText = nice2MeetYous1211;
sell = 0;
updatedAt = "2016-11-21T14:34:11.338Z";
}
因此,我收到了一条错误消息,因为Parse LiveQuery像REST一样返回。
2.当我尝试了“fix-object-decode”的分支时,它返回了PFObject而不是REST样式。但它也不能直接检索我的指针数据。
ios ParseLiveQuery link branch->fix-object-decode
我曾测试 “修复对象解码” 分支。
它返回格式良好的PFObject,但它看起来不同的结果。
这是我原来的PFObject当我通过findObjectInBackGround要求()
<Post: 0x6080000b0800, objectId: w5qcfMCByF, localId: (null)> {
likeCount = 0;
postBy = "<PFUser: 0x6080000e3100, objectId: rgG7XfAYWj, localId: (null)>";
postImg = "<PFFile: 0x60800024c150>";
postText = nice2MeetYous1211;
sell = 0;
}
当我改变postText然后我通过实况查询,但不同了更新事件。
<Post: 0x6100000b1be0, objectId: w5qcfMCByF, localId: (null)> {
likeCount = 0;
postBy = "<PFUser: 0x6100000e6900, objectId: rgG7XfAYWj, localId: (null)>";
postImg = "<PFFile: 0x61000025d1f0>";
postText = nice2MeetYous;
sell = 0;
}
正如你可以see..PFUser:0x6080000e3100和PFFile:0x60800024c150已更改为PFUser:0x6100000e6900,PFFile:0x61000025d1f0
反正当我接收到的事件,我不能fetchObject。
这是关于活查询或分析服务器端问题的问题吗?
由于未捕获异常而终止应用程序'NSInternalInconsistencyException',原因:'密钥“用户名”没有数据。在获取其值之前调用fetchIfNeeded。'
我添加了一些代码以避免fetchIfNeeded错误。
这是我的代码片段。
extension Post: FeedCellSupport {
var username:String?{
do {
try postBy?.fetchIfNeeded()
} catch _ {
print("There was an error")
}
return postBy?["username"] as? String
}
var userImg:PFFile?{
do {
try postBy?.fetchIfNeeded()
} catch _ {
print("There was an error")
}
return postBy?["profileImg"] as? PFFile
}
现在的作品不错,但......系统提示“警告:正在主线程上执行的长期运行的操作”
我想是不是百威..
你能帮我吗?
你介意分享链接吗? – nathan
更新我的评论。 includeKey工作正常。 https://github.com/parse-community/ParseLiveQuery-iOS-OSX/issues/91 –
当然? https://github.com/parse-community/ParseLiveQuery-iOS-OSX/issues/30和https://github.com/parse-community/parse-server/issues/1686 – nathan