Accessing "User Info" dictionary in CoreData from IOS Application - ios

I've created some ManagedObjects and for each of them I added the User Info Key/Value of DisplayName
Example:
Attribute: eReader
User Info Key: DisplayName
User Info Value: E-Reader
Attribute: weather
User Info Key: DisplayName
User Info Value: Weather Radar
I was hoping to Query the entire NSManagedObject from code and then iterate through each attribute and display their DisplayName on the screen. Any guidance as to how to do this?
This way I could show a table of User Readable text but each entry was mapped to the correct NSManagedObject attribute which cannot start with either uppercase or have spaces in them.

I found my answers here UserInfo Dictionaries on CoreData
for (NSString *key in [ei.attributesAsDictionary allKeys]) {
NSAttributeDescription *attributeDescription = eiEd.attributesByName[key];
NSString *displayName = attributeDescription.userInfo[#"DisplayName"];
}

Related

How to retrieve an specific child in Firebase?

The childByAutoId would be useful if you want to save in a node multiple children of the same type, that way each children will have its own unique identifier.
pet:{
KJHBJJHB:{
name:fluffy,
owner:John Smith,
},
KhBHJBJjJ:{
name:fluffy,
owner:Jane Foster,
}
}
Therefore, once I have that uID, and I want to retrieve an specific user using the his/her uID. How do I tell Firebase that I want that specific user? Because I create it and store it in Firebase, but then to read it, don't I need to know the value of the uID? Where do I get it from?
What function do I use to retrieve for example the second user using the uID?
Thanks in advance..
in the title u ask how to get rid so:: get the new ref's key property to get the aid created
FIRDatabaseReference *ref = parent.childByAutoID
NSString *uid = ref.key
BUT thats not what you want id say, so:
to filter out all children where owner = XY which you want I think:
FIRDatabaseReference *ref = your pets node
FIRDatabaseQuery *allPets = [ref queryOrderedByChild:#"owner"];
FIRDatabaseQuery *specificPet = [allPets queryEqualToValue:#"XY"];
[specificPet observeEventType:FEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary *dict = snapshot.value;
NSString *key = snapshot.key;
NSLog(#"key = %# for child %#", key, dict);
}];
see: Query users by name or email address using Firebase (Swift)

Trouble with a Firebase Query

I am new to firebase because parse is shutting down and I have spent days trying to figure out how to find the parent of the child I am trying to query. For example let's say my parent is email and my child is person1. Now in my dictionary person1 is paired with person 1(there is a complicated reason why I am doing this but it is not a problem)
So my code looks like this.
Firebase *fb=[[Firebase alloc]initWithUrl:#"https:firebaseURL"];
[[[fb queryOrderedByChild:#"person1 string"] queryEqualToValue:#"person1 string"]
observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(#"888888%#", snapshot.key);
}];
NOTHING SHOWS
I really would appreciate the help. So basically I need to know how to query based on the child value and find the parent to that child. Thanks everyone.
A couple of things;
Your query is malformed. Ordered by defines what 'field' or node name you want to search.. it's the KEY part of the KEY:VALUE pair.
[fb queryOrderedByChild:#"person1 string"] should be
[fb queryOrderedByChild:#"node name to search"]
Let me break it down
Given
users
uid_0
name: "Jay"
state: "Florida"
uid_1
name: "Leroy"
state: "Colorado"
and code
// a reference to the parent node we want to query
Firebase *usersRef = [self.myRootRef childByAppendingPath:#"users"];
//define which child node name we want to search
FQuery *statesRef = [usersRef queryOrderedByChild:#"state"];
//define the value we want to search for
FQuery *specificStateRef = [statesRef queryEqualToValue:#"Florida"];
[specificStateRef observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(#"snapshot: %#", snapshot);
}];
snapshot will contain
uid_0
name: "Jay"
state: "Florida"
The parent node name is uid_0 and can be retrieved with
NSLog(#" key: %#", snapshot.key);
and the name and state are key value pairs stored in the value
NSLog(#" value: %#", snapshot.value);

Why is Parse PFObject response borked?

I am starting a new project on Parse.
I am trying to retrieve my own properties on a custom class PFObject being returned from a query. I'm using [object objectForKey:#"key"] and it isn't working. I logged the description of the object I was getting back from the query and it's format is:
<Horse: 0x7f93e9c7e240, objectId: gLqeyEfOr6, localId: (null)> {
hidden = 0;
visibleName = "Horsey";
}
Notice that "hidden" and "visibleName" have been encapsulated by { }'s . This seems to be my issue. Why is this format happening to my custom properties? How do I get the data for keys "hidden" and "visibleName" out of my PFObject?
Thanks
You can access a PFObject directly as a dictionary - the {} is just added by the description method (which is the method that gets invoked when you NSLog the object as a string) to indicate a dictionary. What you have should work. You can also use the more compact notation -
NSString *visibleName=myPFObject[#"visibleName"];
NSNumber *hidden=myPFObject[#"hidden"];
What results are you getting when you say "it doesn't work"?

Parse PFUser CurrentUser Returning Null

I save a few objects in the _User class in parse, such as displayname, gender, and bio. A simple user profile. I'm having difficulty retrieving them. I tried with many types of queries with no luck. So I figured if you could get the username by doing this:
self.username.text = [NSString stringWithFormat:#"#""%#",[[PFUsercurrentUser]valueForKey:#"username"]];
You should be able to get other objects that are stored in _User right? Well I tryed this to get the display name:
self.name.text = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"name"]];
And I get (null) printed out on the label, except in the data browser there is a value there. I'm really in need of some assistance this has been a problem that's taking me a while to figure it out. Thanks!
You have mentioned two lines in your code:-
//Have modified this line
In this line valueForKey you are passing #"username"
self.username.text = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"username"]];
In this line valueForKey you are passing #"name"
self.name.text = [NSString stringWithFormat:#"%#",[[PFUser currentUser]valueForKey:#"name"]];
Now in above two line both are having two separate keys username and name. So just check the valid key like that below if you are not sure which is valid, if below any of line prints value then use that key for setting the value in your label:-
NSLog(#"%#",[[PFUser currentUser]valueForKey:#"username"]);
NSLog(#"%#",[[PFUser currentUser]valueForKey:#"name"]);

Get whole object from NSMutableDictionary for current cellForRowAtIndexPath and assign it to a CustomCell

I have the following type of a NSMutableDictionary
(
{
id = 1;
key = value;
key = value;
},
{
id = 2;
key = value;
key = value;
}
)
It contains multiple data of an own Object. Now, in cellForRowAtIndexPath. I created a CustomCell that has a field CustomCell.customObject that should get this object. What I'm trying to do is the following. I want to assign the current entry of the NSMutableDictionary to this field.
Alternatively I could do this (and am doing it right now)
I'm getting the ID like this
NSString *objectId = [[dict valueForKey:#"id"] objectAtIndex:indexPath.row];
And then I'm loading the object from the database. The problem I'm seeing in this, is the doubled request. I mean, I already have the data in my NSMutableDictionary, so why should I request it again?
I don't want to just assign a certain key-value pair, I want to assign the whole current object entry of the NSMutableDictionary. How would I do this?
If the above code (dictionary) is used to show information on tableview there is a mistake in it dictionary should always starts with "Key" not with index. So better make the dictionary to array and then you will have index to get complete information in indexes write this code
NSLog(#"%#",[[newArray objectAtIndex:0]objectForKey:#"id"]);
Hope this will help..

Resources