I am using the Parse.com Store template and I am having trouble accessing parts of my data browser. I need to access a column called 'link' from the data browser and I do not seem to be able to. If I run linkLabel.text = self.product[#"link"]; and then NSLog it NSLog(#"%#", linkLabel.text]);
The value is returned as null.
So I decided to check what the value of 'link' is. I ran NSLog(#"%#", self.product[#"link"]); and still it returned null. I thought well there is something wrong with 'link' so i tried 'name' NSLog(#"%#", self.product[#"name"]);still... nothing (it returns (null)).
So I have no idea how to access link or name from my ViewController. I have even added #property (nonatomic, strong) PFObject *product; and still nothing.
I am able to access all of those objects but they do not get accessed by the servers. Now in my other view (that Parse.com built) when I run linkLabel.text = self.product[#"link"]; and then log it I get the value off of my data browser. So Basically I am doing something wrong and I need help! Thank you so much!
To access your data from parse ,you need to fire query and in return you get data for which you have provided a condition. Here's go with this link and parse and also go for google. You will find your way to fetch your data from parse. After receiving data you could populate the label's or view controller you want to.
Related
I am using the realtime database (not firestore). This is the set of data in my database I am trying to retreive:
What I actually get is this:
As you can see the questions node has one item in the database, but when I get the data, it is an empty object. Can anyone tell me why?
Solution
My problem was I had missing data on the questions node when retrieving a data set from Firebase. The reason that data was "missing" was because I had a piece of code assessment.questions = {}; that was resetting that node to an empty object after it was retrieved from the database. I removed that piece of code and the property assessment.questions correctly contained the data I was missing.
I'm creating two PFObjects at the same time that should reference each other's object IDs when they're saved. In the example below, the second object is supposed to save the first object's object ID in an array.
let objectForFirstClass = PFObject(className:"ClassOne")
let objectForSecondClass = PFObject(className: "ClassTwo")
objectForSecondClass.setObject([objectForFirstClass.objectId!], forKey: "classOneObjectArray")
The last line is causing the error because objectForFirstClass.objectId is nil. I'd assume this is because the object hasn't been saved yet. How can I fix this?
You want to save after creating the first object, and in the completion handler, create the second one with a reference to the first one.
You can use saveAllInBackground:block: for this.
Correct, the object id is assigned by the server when saved. I'd be tempted to write some cloud code to do what you want so you can send some details and the cloud code will create and connect the objects, then return both of them to you. You can of course do the same thing locally in your app, there's just more network comms.
You should also consider using pointers or relationships. These are better for querying, though the same save requirements apply before you can set the connections.
I've researched tons of questions and documents about CoreData returning faults instead of actual values:
Relationship 'whiskers' fault on managed object (0xb7abab0)
This happens when I'm trying to get the count for the number of whiskers, such as:
self.numWhiskersLabel.text = [NSString stringWithFormat:#"%d", cat.whiskers.count];
Even if I try to log the whiskers set directly I still get a fault:
NSLog(#"whiskers: %#", cat.whiskers);
I understand that "Core data will not return full object until there is a need to access the actual value of that object. Each of your returned objects will be a 'fault' until this point." That's great, but there is a need to access the actual value at this point. I need the value right now! So how do I get out of this oxymoron? How can accessing the count of a Set not be considered needing the value?
I didn't get any feedback from my comment so I'm just going to assume whiskers is a set of NSManagedObjects
The set wont be loaded initially because internally it's coming from another table in the db. When you access .whiskers.count it still doesn't need to go and get the data yet, because all you're wanting is the number of whiskers in the set.
When you pull a whisker out of the set, then it will be faulted, try doing
NSLog(#"whiskers: %#", [cat.whiskers.anyObject anyProperty]);
That should give you a loaded NSManagedObject.
This is an error condition. Something is wrong with that NSManagedObject instance. Either it was deleted before you accessed it or you are trying to touch it from the wrong thread.
Please edit your question and show the code that is accessing that NSManagedObject.
Also, what happens when, in the debugger, you just do a po cat? Do you see the full Cat object or is that giving a fault error as well?
When I implement the getLoggedInUserOnSuccess:onFailure method (or the loginWithUsername: password: onSuccess:^(NSDictionary *results)...method in xcode, the results array does not become available until after all of my code has finished running. (If I NSLog the results, they will show up correctly.)
There is one other question that mentions this in Stackoverflow:
How to get the sm_owner User object using StackMob as backend
However, the Stackmob Evangelist in the answer here does not suggest that there is any requirement for a completion block or something of this nature. (And in fact, in his own code, it appears to work without such a block or any sort of "waiting.") This was my first hunch as to what might be going wrong.
(Without posting a ton of code, I am trying to use this function to get the sm_owner which then serves as the predicate in the FetchedResultsController's getter, to ensure the user only sees their own creations and not those of other users, when in one view; in another fetch, they might be able to see the creations of users they follow.)
Has anyone else tried to use one of these methods with a results dictionary returned to write the predicate on a FetchedResultsController or similar and been able to make it work?
None of the Stackmob tutorials appear to limit data returned from a database based on its creator as far as I can tell.
If you set your schema's read permissions to "Allow to sm_owner", then you don't need to place a predicate on the fetch. Doing a generic fetch will return only those objects owned by the current logged in user.
All,
I am trying to solve an issue now for the last two days and seem incapable. Apologies in advance if asking for the obvious.
In a very simple data model I try to insert a new object user. (attributes: name, password and id which are respectively a NSString, a NSString and a NSNumber). The new object gets successfully created
in the API and the external MySQL server. However, in the completion block of the HTTPrequest when
(I think) the backing store is populated it tries to create the resource identifier.
This is were the app crashes in this method when it is trying to get allKeys from the representation dictionary:
(NSString *)resourceIdentifierForRepresentation:(NSDictionary *)representation ofEntity:(NSEntityDescription *)entity fromResponse:(NSHTTPURLResponse *)response
The JSON response getting back from the server is as follows:
[{"id":20,"name":"john doe","password":"secret"}]
Anyone a clue? Would be very grateful if I could solve the issue this year!!!
Side notes: Matt great job!
Side question: How will AFIS deal with local storage, local changes and synching with the server when a connection is back?
All,
Thanks in advance and enjoy 2013!!!
[Update]
The issue is that I get an NSArray back instead of a NSDictionary. I can simply fix it by changing the code in AFIS savecontext to pass the responseObject[0] however I prefer not to change the AFIS code and I still find it odd that I dont get an NSDictionary back when I have a valid JSON response
You can override the method that AFIS uses to get the resulting object from the json data.
- (id)representationOrArrayOfRepresentationsOfEntity:(NSEntityDescription*)entity
fromResponseObject:(id)responseObject
The response object should be your array with dictionary at index 0.