AmityObject
instance and LiveCollection is represented by an instance of AmityCollection
. They are generic classes which encapsulates any other object and notify observer whenever any property of encapsulated object changes. AmityObject<AmityPost>
or AmityCollection<AmityMessage>
.AmityObject
and AmityCollection
provide methods that help observe changes in objects. The life cycle of observation is tied to its token. As soon as the token is invalidated or deallocated, observation ends.AmityNotificationToken
is a simple object which keeps track of what is being observed. Each observation from live object or live collection is tied to its respective token. As soon as the token is invalidated or deallocated, observation ends. The token is declared within the scope of the class.AmityNotification
is alive in MyClass
scope.AmityObject
is a generic class that keeps track of a single object. It is a live object. In iOS AmitySDK
, any object which is encapsulated by AmityObject
is a live object. AmityObject<AmityMessage>
AmityObject<AmityChannel>
AmityObject
class exposes the following methods:observe
observeOnce
observe
method can be triggered multiple times throughout the lifetime of the application as long as its associated AmityNotificationToken
is retained in memory. observeOnce
method, on the other hand, can only be triggered once. observe
and observeOnce
methods will be called from the main thread so you can perform any UI update-related tasks from within the observe block itself.dataStatus
property of AmityObject
.observe
and observeOnce
block will be retained using token as shown below.AmityNotificationToken
provides a method called invalidate()
which can be used to invalidate the token anytime. As soon as you invalidate the token, your observation stops and observe block will no longer be triggered.AmityObject
. AmityObject
exposes the following properties:dataStatus
: This defines whether data is fresh or local.loadingStatus
: This tells if the data is being loaded from server or not.object
: The actual object that is being tracked or encapsulated by this AmityObjectForobserverOnce
method, if data is present locally, this observer will be triggered only once with that local data. If you are looking for fresh data, use theobserve
block and invalidate the token once fresh data is received as shown above.
object
property from AmityObject directly.observe
or observeOnce
block depending on your requirement.AmityCollection
is a generic class that keeps track of a collection of objects. It is a Live Collection. In iOS SDK, any object which is encapsulated by AmityCollection
class is a live collection. AmityCollection<AmityMessage>
AmityCollection<AmityChannel>
AmityCollection
exposes these methods:observe
observeOnce
observe
method can get triggered multiple times throughout the lifetime of the application as long as its associated AmityNotificationToken
is retained in memory.observeOnce, on the other hand,
can only be triggered once. observe
and observeOnce
method will be called from the main thread so you can perform any UI update related task within the observe block itself.dataStatus
property of AmityCollection
.observe
and observeOnce
block should be retained. You can refer to the section in AmityObject about retaining and invalidating a token.AmityCollection
does not return all data in an array. Instead, data are fetched one by one using the objectAtIndex:
method. This allows the framework to store most of the actual result on disk, and load them in memory only when necessary. AmityCollection
also exposes a count
property which determines the number of objects present in a collection. AmityObject
, AmityCollection
also exposes dataStatus
and loadingStatus
property.dataStatus
property and invalidate the token once you have accessed your desired collection data.ForobserverOnce
method, if data is present locally, this observer will be triggered only once with that local data. If you are looking for fresh data, useobserve
block and invalidate the token once fresh data is received as shown above.
AmityCollectionChange
object which contains indexes of what is added, deleted, or modified in a collection. You can also refer to these properties to update the UI for the list.liveCollection.object(at:)
to access a single item, you might often find the need to iterate through all objects in the collection. The SDK has a convenient way to do this using .allObjects()
..allObjects()
.allObjects()
AmityCollection
in SDK returns a maximum of 20 items per page. It has nextPage()
and previousPage()
method to fetch more data. It also exposes hasNext
and hasPrevious
property to check if next page or previous page is present.nextPage()
/ previousPage()
to load more dataobserve
block gets triggered and you can access the collection as shown above. If you want to shrink the collection to the original first page, you can do so by calling resetPage()
method on the same collection.UITableView
. Below is an example of fetching a collection and displaying it in a tableview.UITableView