Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

I'm using in tableview with swift3. Could you anyone some helps me? #85

Closed
ShawnBaek opened this issue Nov 18, 2016 · 5 comments
Closed

Comments

@ShawnBaek
Copy link

Hi I'm trying to use live query.

My question is really simple. Could you please let me know how do I use that?

My original code is here

in Tableviewcontroller

loadPost(){
blah blah~~~

   //Get All of Post
    let postQuery = PFQuery.orQuery(withSubqueries: [friendsPostQuery, myPostQuery, sellPostQuery])
    postQuery.includeKeys(["postBy", "comment", "comment.commentBy"])
    postQuery.limit = self.page
    postQuery.addDescendingOrder("createdAt")
    
    postQuery.findObjectsInBackground { (objects:[PFObject]?, error:Error?) in blah blah~~~

}

I want subscribe of postQuery.

So I changed my code like this

Step 1. Make "Post" Class
class Post: PFObject, PFSubclassing

Step 2. declare subscription variable in tableviewcontroller and postQuery variable.

var postQuery: PFQuery? {

    return Post.query()?
        .whereKey("hi", equalTo: "Something")
    <-- How do I set like loadPost()?
}

//Post Subscription
private var subscription: Subscription<Post>?

Could you please let me know some guide?

And Can I use live query with swift3?

@flovilmart
Copy link
Contributor

Hi, there is an example here for a generic LiveTableViewController: https://github.com/flovilmart/cocoaheads-mtl-parse-server/blob/master/ios/CocoaHeaders/LiveTableViewController.swift

@ShawnBaek
Copy link
Author

ShawnBaek commented Nov 19, 2016

@flovilmart

Thanks for sharing your code.

I'm trying to use your code but I got an errors.

when Init() -> FatalError()

My snippet code

Could you please advising me?

@flovilmart
Copy link
Contributor

What's the fatalError?

@ShawnBaek
Copy link
Author

I found it. It just happened I didn't set initialize TableViewController. My mistake..

But I'm struggling to implementation. Could you advising me?

My app has consist of 5 tabs and 5 viewController(Table, Collection, View, etc..).

I want implement livequery in my first tab as TableViewController.

Then where I put this code? in NavigationController? or TabController?

  // Create the liveQueryClient
    client = ParseLiveQuery.Client.shared

    let query = Post.query() as! PFQuery<Post>
    query.whereKeyExists("objectId")

    let liveQueryController = FeedVC(query: query, client: client)

    viewControllers = [liveQueryController]

And Is there a way to use without required init() in FeedVC?

Here is what I'm trying to do it. And fetchObjects() is not called.
https://gist.github.com/yoshiboarder/0c4060d483f0b04e3195a5e3ed19d7ed

Thanks

@flovilmart
Copy link
Contributor

For implementation details, you should probably as over stackoverflow

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants