How to store a list of list of live queries

Sorry if it’s more of a Swift question but I can’t figure out how to google for this question :grin:

I created a few live query objects on different classes and I’d like to create a list of all of them (so that I can unsubscribe later). How would that work in Swift?

let liveQuery = Library.query("updatedAt" > since)
let liveQueries: ??? = []
liveQueries.append(liveQuery)

Similarly, I’ve been unable to create an array of ParseObjects as it is a protocol, do I have to create by own base object if I want to store them in an array?

For your object, create an empty protocol and make all of your objects you want in the array conform to your new protocol:


protocol LibraryType { }

struct Library: ParseObject, LibraryType {
...
}

struct Book: ParseObject, LibraryType {
...
}

let array: [LibraryType] = [library, book]

You can’t make an array of ParseObject because it requires self. You can see I did something similar to this in the SDK with ParseType:

Technically you can automatically make an array using ParseType, but I don’t recommend depending on that as ParseType isn’t documented because it’s not meant for developers to use. If we change ParseType to something else, it could break your code. So you should create your own protocol.

For subscriptions you will most likely need to do something similar to the testcase below (there are many in the file if you need more):

OK Thanks I’ll digest this all.