Problem: I cannot create new PFObjects objectWithoutDataWithClassName:objectId: in swift, is this possible and if so how?
Context: I have a stored array of objectIds of parse objects that I want to use to populate a view but first I have to get each object from parse. Rather than making 'n' number of network requests on parse for each object I want to instead make an array of PFObjects using Parse's objectWithoutDataWithClassName:objectId: functionality and then call [PFObject fetchAllInBackground:block:] with the array. However, in swift it does not appear as though PFObject.objectWithoutDataWithClassname exists. Has anyone encountered this/know how to do this in swift....?
Thanks in advance.
You can use
PFObject(withoutDataWithClassName: <String>, objectId: <String?>)
This method became an initializer.
Related
In Parse, I have an object which has a key that is an array of pointers to other objects. How do I delete one of the pointers without deleting the entire array and without deleting the actual object?
if you use the removeObject:forKey: method of PFObject, it removes the item from your array but won't delete the pointer.
That's obj-c, btw, I'm not familiar with the Swift SDK.
You should read into the API Guide a bit for PFObjects and PFQueries. It'll answer a lot of questions you have before you ask them.
https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/removeObjectForKey:
I just learned how to store an array into a Parse Cloud using the example provided by the Parse Documentation:
gameScore.addUniqueObjectsFromArray(["flying", "kungfu"], forKey:"skills")
gameScore.saveInBackground()
Now, utilizing this logic, I want to append strings into the array. So this is what I wrote:
#IBAction func requestButtonPressed(sender: AnyObject) {
var prayerRequests = PFObject(className: "PrayerRequests")
prayerRequests.addObject(["YOIDJFO"], forKey:"skills")
prayerRequests.saveInBackground()
}
Now, after having executed the function requestButtonPressed three times, in parse this is happening:
However. I don't want that to happen when I execute the function requestButtonPressed three times. I want it to be something like this:
Anybody have a solution to this problem?
Every time you use this statement var prayerRequests = PFObject(className: "PrayerRequests") a new PFObject will be created. In order to update a object you need to query the object first and then update its field. In your case you should first get the array by querying for the object, modify / append data to the array and then update the object.
Instead of doing addObject, do insertObject:{yourObject} atIndexPath:{storingPosition} forKey:{#"youKey"}.
And the the value you are adding is an array ["YOIDJFO"] , object should be like {"YOIDJFO"}
I need to run a SYNCHRONOUS call to parse.com. This is what I got:
var query = PFQuery(className:"myClass")
query.whereKey("groupClassId", equalTo:self.currentGroupId)
query.selectKeys(["objectId", "firstName", "lastName"])
self.arrayCurrentData = query.findObjects() as Array<myData>
This return the correct number of rows from parse.com and fills up my local array. But how can I extract the data from the array? If I look at the array at runtime it shows that all the data I need is in 'serverData' in self.arrayCurrentData.
Normally if I loop an async(findObjectsInBackgroundWithBlock) filled array I would ask
self.arrayCurrentData[i].lastName
to get the lastName, but that is not the case in the sync array. There I can't ask directly for values (or so it seems).
Anyone who know what I am talking about and how to get data synchronous from parse.com?
Get the PFObject's attributes with valueForKey(). This is true whether or not the object was fetched synchronously. In other words...
self.arrayCurrentData[i].valueForKey("lastName")
EDIT - This approach generates a compiler message because you've typed the response as Array<myData>. But find returns PFObjects, so ...
self.arrayCurrentData = query.findObjects() as [PFObject]
... is the correct cast. I'm not a swift speaker, but the expression self.arrayCurrentData[i].lastName pleases the compiler because arrayCurrentData[i] is typed as myData. But this fails at run time because the real returned objects are PFObjects.
As an aside, I'd take a hard look at the rationale for fetching synchronously. I can't think of a case where its a good idea on the main thread. (off the main okay, but then you've already opted for asynch vs. the main, and the block-based methods provide a good way to encapsulate the post-fetch logic).
I'm using Realm.io as database and I need a select * from all_tables in Realm.
I mean a method returning an RLMArray, but I have not found anything about this.
I need the class reference, such as Realm Browser.
Thanks.
You can use [realm.schema.objectSchema valueForKey:#"className"] to get an NSArray of all of the RLMObject subclasses used in the Realm.
I don't believe this is possible at the moment. You should request it on github. In the mean time you will have to create your own. First you have to know that an RLMArray can only hold one type so if in these different tables there are different types than you can not do the following. It would be as easy as creating your own method for this. It would consist of getting all objects from each table and just inserting them into the RLMArray; If your tables don't have the same type then you will have to use a NSMutableArray or an NSArray.
I'm using Parse as the backend for my app. My app will be used in the field where service will nonexistent or spotty at best so I need to store information offline. I currently save data for the user in a plist in the background (Title, location coordinates, notes, additional data). Since Parse's current iOS offline saving is fairly poor (From what I've read), I was hoping to get around it by creating an array or dictionary from the plist and upload that to Parse by giving it an array once the user is back in cell range.
As it occurs now, when I upload the array, it simply puts the entire contents of the array in a single cell in the database. Is there a way to parse the array and create a new row for each entry/object in the array?
I may have overlooked a better way to do this. If someone has a suggestion I would appreciate it!
I solved it. I iterated through the array using a for loop and added each index as a separate object.