QuickBlox update custom object without using ID - ios

I use QuickBlox for my chat app.
When updating/deleting a custom object, is it possible not to use object.ID?
For example, I use a custom field "requestor_id" and "responder_id" to identify FriendRequest Custom Object. I need to update the status of a friend request to from "pending" to "approved".
I don't want to fetch the ID first in order to update it.
Is it possible to send along a dictionary like #{"responder_id": 123, #"requestor_id":234}?

I think it's not possible. Deleting or updating take place only with object's ID.. so you need perform at last 2 actions:
fetch items
updating/deleting

Related

When I try to save data to Firebase it only updates the existing data, Swift, Firebase

The way I set up my database structure was like this:
It starts with Lists then there is a child that shows the users UID then inside that there is one item.
The one item inside the UID gets updated every time I attempt to save new data. Instead of adding another item the same one just keeps changing. I was wondering how I could instead of update the same one item every time add more items.
The way that I save my data is with this line of code.
let user = FIRAuth.auth()?.currentUser
let item: String = self.ItemTextField.text!
self.ref.child("Lists").child(user!.uid).setValue(["Items": item])
More idiomatic is to store the list of items with so-called push ids:
Lists
twEymn...
-Km....: "Yoghurt"
You'd do this with:
self.ref.child("Lists").child(user!.uid).childByAutoId().setValue(item)
The childByAutoId() generates a unique, sequential ID. It's similar to an array index, but this one works reliably in multi-user environments and when users can be offline. Read this blog post about these so-called push ids.
Alternatively you can use the name of the item as the key (if the item has to be unique in the list):
Lists
twEymn...
"Yoghurt": true
In that case the code becomes:
self.ref.child("Lists").child(user!.uid).child(item).setValue(true)
One thing you'll note is that both of these approaches only deal with the newly added item, instead of the list of items as a whole. This is a general pattern you'll see when using Firebase. By isolating your modifications, your app will be more scalable without users getting into each other's way.
The problem is that you are setting a key-value pair ("Items" : item) so that each time it is updating the value for the same key. What you could do instead is ("Items" : [your array of items here]), which will update a list of items for the same key each time.
You could also fetch the current list of items, append your new item locally, and then update.

How to fetch a custom attribute from Kinvey

I am looking to fetch a custom attribute I added to a user called "PostCount". I am looking to fetch it and set it to a label to view the post count. I successfully can increment the active user's PostCount but am unsuccessful at fetching it to display it.
Here is what I think I should be using.
var query = KCSQuery(onField: "PostCount", usingConditional: KCSQueryConditional.KCSAll, forValue: 4)
store.queryWithQuery(query, withCompletionBlock: "Not sure what to do here",withProgressBlock: "or here")
I think I need to use this, but I am not sure what the completionBlock or progressBlock would be.
Because it was a custom attribute under the user, it did not use the KCSQuery(). Instead I did the following
KCSUser.activeUser().getValueForAttribute("PostCount")
This retrieved the number stored in my post count, which I then set to the label I was displaying.

Listen to custom object - QuickBlox

I've managed to add/edit/delete/update custom objects in the QuickBlox back-end.
However, I want the user to "listen" to a certain object, and if the value has changed I want to let the user know.
Is that possible?
Thank you!
There is only one way to "listen" for any changes on custom objects: there is property updatedAt, but you need to load custom object from server (by QBRequest) in order to get this field up to date from server.

Do I have to fetch the object first in order to update a meta-data field in parse.com

In Parse.com, the help document for updating an object seems to require a query first to retrieve the object before one can update the meta data.
Given that I know the objectId of the object I am updating, do I still have to make this additional call to retrieve everything else about the object before I can send an update call (via saveInBackground)?
Yes, you do. In order to update an object from parse, you must have a local copy.
In order to make a call to update an object - which can take several forms of save or saveInBackground or saveEventually, etc. - you must first make a query to have a copy of the object.
If you know the objectId, is sounds like you have already run a query on an associated object - why not get the full object then with an includeKey: call? https://www.parse.com/docs/ios_guide#queries-relational/iOS

Sending NSNotifications to all objects of a class

I have an object that can be selected by a user click. With the current requirements of the app, at any time, there is no more than one of these items selected at any point during app execution.
I implemented a mechanism to enforce this, as follows:
Each of these objects has a unique identifier as a property.
When each object is created, it subscribes to the NSNotificationCenter listening for the MY_OBJECT_SELECTED notification.
When each object is selected, it posts the MY_OBJECT_SELECTED notification, with its unique Id as part of the userInfo dictionary.
Then, when each object receives the notification, it checks to see if its id is the same as the one in the userInfo. If it is, it does nothing, but if it isn't, it sets itself to unselected.
Is this a decent approach to the problem? If not, how would you do it?
It is a decent way of doing it, although it is not very efficient. The more objects you have, the more time you spend comparing IDs. The easiest way is to store your object pointers and IDs in a map table (or similar) and remember the last selected object. Whenever you select a new object, you clear the selection flag of the last selected object, then look up the new object and set its selection flag. It requires you to keep a collection of your objects, though.
The time required to update selections with this approach is independent of the number of objects you have.
If the object is spread all over the app,i.e. if it is a member in various classes. You can have a global object of same type and assign it to only that object which has been touched. In steps it will be like:
Have a global variable of object type.
At any object touch assign globalObject = currentObject;
do all operations on globalObject throughout app like calling methods and modifying object members(have a check for nil to ensure safety).
Reassign to different object with new touch.

Resources