Is it possible to edit a string in a class on the Parse dashboard? For example, I have the following code:
PFObject *announcement1 = [PFObject objectWithClassName:#"Announcement1"];
announcement1[#"Body"] = #"Changes to training progression";
[announcement1 saveInBackground];
Essentially what I am trying to do is treat Parse like a database. I create a PFObject, call the class "Announcement1" and display the string "Body" in a label.
I've already created the query to pull the "Body" string in the label:
PFQuery *announcement1Query = [PFQuery queryWithClassName:#"Announcement1"];
[announcement1Query getObjectInBackgroundWithId:#"GvuO1ZUYwR"];
NSString *announcement1BodyText = announcement1[#"Body"];
announcement1Label.text = announcement1BodyText;
Now my question is, would it be possible to then go into my Parse dashboard and edit the "Body" string so as to update the label live with new information each time? If not, what would be the best way to go about doing this?
Thanks, Mustafa
Yes. You can update data in parse using dashboard. Parse doesn't support realtime DB, so you need to query the object or refresh object again to see the real data.
Related
Assume we have simple data model with single entity User; simple tableView_friends with fetchedResultsController_friends for show users - friends.
Assume we have search bar for searching all (not only friends) users in service, and for every typed in it character we perform search request to server, which return to us somehow filtered by character User objects. Some of this objects can already be inside local database. By app logic we don't really must save all this results in local database forever (but ok, we can, we can clear local database time to time); on other hand, if we will perform any action on some searched user, we must store this user. We want to show list of searched user in other tableView_search with fetchedResultsController_search.
Question: should I use same context for fetchedResultsController_friends and fetchedResultsController_search? If no, how can I handle situation, when I wish to edit searched user, which already exists in database and probably already local edited? If yes, how can I setup predicate for fetchedResultsController_search (server perform its own logic for search by character, which can be changed) for show exactly same result as from server?
We recently implemented a search feature in our application and had a similar issue, We had local data in core data and also remote data from our API.
You have a few options that we explored:
Save your data into core data from the API as it is retreived and
then the fetched results controller will do the rest
Manage the merge of the data yourself, you can still use NSFetchedResults controller to an extent but need to do more work
We didn't want to save all of the information returned from the API unless it was needed (the user selected it), so we come up with a simple solution that worked for our app. This may not work directly for your app, you may need a completely different solution or change some of the things we done to suit.
Firstly, To explain what we are dealing with, we had a Article entity in core data which contains around 25 properties, the API returns article objects as JSON data with the same data.
What we decided to do was to create a class which represents a simple version of an article (just enough data to show in a list view and reference it later in the API or core data) which looked something like this:
class SearchResult: NSObject {
var id:String?
var title:String?
var imageUrl:String?
var url:String?
// core data entity
init(article:Article) {
self.id = content.contentId
self.title = content.title
self.featuredImageURL = content.absoluteImagePath()
self.urlAlias = content.urlAlias
self.publishedAt = content.publishedAt
}
init(articleDictionary:NSDictionary) {
self.id = articleDictionary.objectForKeyNotNull("id") as? String
self.title = articleDictionary.objectForKeyNotNull("title") as? String
self.url = articleDictionary.objectForKeyNotNull("url") as? String
if let imageUrl = articleDictionary.objectForKeyNotNull("imageUrl") as? String {
self.imageUrl = imageUrl
}
}
}
Now using this, we can create once of these from either the core data results or from the API results. Our tableview datasource is just an array
var dataSet = [SearchResult]()
We use the NSFectchResultsController delegate methods to add/remove/re-order core data elements from the dataSet after the initial load and when we get API data we'll do something like:
dataSet = Array(Set(apiResponseArray + dataSet))
This will take an array of SearchResult items from the API, merge them with the current result set and remove duplicates. casting to a set and then back to an array will give you an array of unique results as a Set is made of unique values only.
See this reference which should help with how the delegate methods would work
i registered a User with PFUser and now i want to add a PfObject for each User something different, so like User A has in the PFObject the number 5 and User B has in the Object the number 8. How can i do that ? I used the PFSignUpViewController sample from Parse
If you are using Objective-c, use this code to create a random number.
int r = arc4random_uniform(74);
Then save the r to the user, the same way you save username and password.
user[#"randomnumber"] = r;
All users have a objectId in parse, so i donĀ“t see the point in doing what you are doing. And most of the information you need can be found in the docs.
https://parse.com/docs/ios/guide#users
I'm quite new to Firebase and Swift and I'm having some trouble when it comes to querying.
So there are basically two things I'd like to do:
Query my users and find only those that contain a certain String in their name (or email address) and add them to an array.
Get all of my users and add them to an array.
The relevant part of my data for this question looks like this:
As you can see, I'm using the simplelogin of Firebase (later I'd like too add Facebook login) and I'm storing my users by their uid.
A part of my rules file looks like this:
"registered_users": {
".read": true,
".write": true,
".indexOn": ["name"]
}
So everybody should have read and write access to this part of my data.
I also read the "Retrieving Data" part of the Firebase iOS Guide on their website and according to that guide, my code on getting all the users names and email addresses should work, at least I think so. But it doesn't. Here is my code:
func getUsersFromFirebase() {
let registeredUserRef = firebaseRef.childByAppendingPath("registered_users")
registeredUserRef.queryOrderedByChild("name").observeSingleEventOfType(.Value, withBlock: { snapshot in
if let email = snapshot.value["email"] as? String {
println("\(snapshot.key) has Email: \(email)")
}
if let name = snapshot.value["name"] as? String {
println("\(snapshot.key) has Name: \(name)")
}
})
}
I noticed, that in the firebase guide, they always used the type ChildAdded and not Value, but for me Value makes more sense. The output with Value is nothing and the output with ChildAdded is only one user, namely the one that is logged in right now.
So my questions are:
Can I do this query with my current data structure or do I have to get rid of storying the users by their uid?
If yes, how would I have to change my code, to make it work?
If no, what would be the best way to store my users and make querying them by name possible?
How can I query for e.g. "muster" and get only the user simplelogin:1 (Max Mustermann)?
I hope my description is detailed enough. Thx in advance for your help.
Supplement:
The weird thing is, that the "Retrieving Data" guide says, that querying and sorting the following data by height is possible.
Data:
Querying code:
And isn't that exactly the same that I intent to do?
I have run into similar situations where I wanted to pull out data from child nodes.
https://groups.google.com/d/msg/firebase-talk/Wgaf-OIc79o/avhmN97UgP4J
The first thing I can recommend is to not think of Firebase query's as SQL queries as they are not. They are like a light duty query.
Secondly, you need to flatten your data if you want to query, as a query only goes one level deep (can't really query data in child notes)
Lastly - if you don't want to flatten your data, one conceptual option to answer your question;
If possible, ObserveSingleEventOfType:FEventTypeValue on the
registered users node. This will read all of the registered users into a snapshot.
Iterate over the snapshot and read each user into an array (as dictionary objects)
Then use NSPredicate to extract an array of users that you want.
I've run numerous tests and performance wise, it's negligible unless you have thousands of users.
Hope that helps!
To answer your questions
1) Yes, you can query with your current structure. A query can go 1 child deep, but not within a child's children.
2) If yes, how would I have to change my code, to make it work?
Here's a quickie that queries by a users last name:
Firebase *usersNodeRef = your users node 'registered_users'
FQuery *allUsersRef = [usersNodeRef queryOrderedByChild:#"lastName"];
FQuery *specificUserRef = [allUsers queryEqualToValue:#"aLastName"];
[specificUser observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSDictionary *dict = snapshot.value;
NSString *key = snapshot.key;
NSLog(#"key = %# for child %#", key, dict);
}];
How can I query for e.g. "muster" and get only the user simplelogin:1 (Max Mustermann)?
In your uses node structure, the users are store in nodes with a key.. the key is the simplelogin:1 etc. snapshot.key will reveal that. So it's key/value pair deal...
value = snapshot.value
key = snapshot.key
I would like to create database in parse.com for simple application.
where I will have four cells in first view
if I click on any cell, it will go to the next screen and contains some more cells. it goes on like that .
Problem is I have never worked with parse database creation .
can some one help...
database creation is very easy using parse.com. A table is termed as an object in parse. To create a table/object use
PFObject *gameScore = [PFObject objectWithClassName:#"GameScore"];
gameScore[#"score"] = #1337;
gameScore[#"playerName"] = #"Sean Plott";
gameScore[#"cheatMode"] = #NO;
[gameScore saveInBackground];
As this code executes from your Ios app you will see a table "GameScore" with attributes "score", "playerName" and "cheatMode" on your parse data browser.
In the same way you can create different tables.
You can also create a primary(unique) key for each of your table and can link them using those keys.
ios parse.com
Try this Appcoda tutorials
http://www.appcoda.com/ios-programming-app-backend-parse/
and also check parse official site as well
https://parse.com/docs/ios_guide#top/iOS
I have dug through a few of the tutorials at parse.com and I don't have a problem with users creating objects and storing them in Parse.
What I don't know how to do is passing an object to another user. So, for example, if I have users with their own to do lists, and a friend wants to add to another users' to do list, how would I go about doing that? So one user would create the object:
PFObject *task = [PFObject objectWithClassName:#"ToDo"];
[task setObject:#"Do the dishes" forKey:#"userName"];
[task save];
But I'd like this user to pass the task to a friend of theirs, so when their friend launches the app, they see the task added to their list.
I'm using the Facebook SDK as well, so if there's something there that could help, I could use that.
I haven't used Core Data before, so I was hoping to handle a lot of the backend work with parse so I could avoid the learning curve for the time being.
Thanks for all the help
I'd like to add that I'm not necessarily looking for an "answer". I just haven't done anything like this before so, I wouldn't know where to look.
You want to use user pointers & ACLs for this.
// assume PFUser *assigned
PFACL *acl = [PFACL ACLWithUser:PFUser.currentUser];
[acl setReadAccess:YES forUser:assigned];
PFObject *todo = [PFObject objectWithClassName:#"Todo"];
todo[#"task"] = #"Wash dishes";
todo[#"user"] = assigned;
todo.ACL = acl;
[todo saveInBackground];
Now, you can see all TODOs with
[PFQuery queryWithClassName:#"Todo"];
You can see all queries which are assigned to you with
[query whereKey:#"user" equalTo:PFUser.currentUser];
And only the creator of a TODO can edit it.
It seems that you have a many to many relationship here : a user can own many todo objects and a todo object can be own by many users.
This kind of approach can be handle with PFRelation object. Take a look at the official blog post here : http://blog.parse.com/2012/05/17/new-many-to-many/
I wouldn't handle it as a many to many relationship in this case.
The person who creates the todo object should be the only owner. You can add an attribute to the todo object and it's type can be an array. The array can then keep track of who it's shared with. If someone it's shared with deleted it you can then just remove them from the array or if the owner deletes it the object can just be deleted.