0

I need to get all the objects in one Coulomb in parse. say for instance i have class in parse with the coulombs : City, StreetCode , Suburb. Now i want all the objects under City in an array.

The array should add all the objects under City:

Should return Array :City1,City2,City3,City4 etc.

Ive found this code to get all the objects in the Class:

PFQuery *query = [PFQuery queryWithClassName:@"StreetCodes"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
    if (!error)
    {

        NSLog(@"%@",allObjects);
        // The find succeeded. The first 100 objects are available in objects
    } else
    {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

but this code returns :

<StreetCodes: 0x7c1d76e0, objectId: dpFuJgeRnB, localId: (null)> {\n    City = KWANOBUHLE;\n    StreetCode = 6242;\n    Suburb = \"10TH AVENUE\";\n}",
    "<StreetCodes: 0x7c638020, objectId: OE9MtOGpVd, localId: (null)> {\n    City = KWANOBUHLE;\n    StreetCode = 6242;\n    Suburb = \"1ST AVENUE\";\n}",
    "<StreetCodes: 0x7c1cf970, objectId: 16TMG5V3jS, localId: (null)> {\n    City = DURBAN;\n    StreetCode = 4091;\n    Suburb = \"45TH CUTTING\";\n}",
    "<StreetCodes: 0x7c1c1dd0, objectId: 0Vk6oav0Zt, localId: (null)> {\n    City = RIVERSDALE;\n    StreetCode = 6670;\n    Suburb = AALWYNFLEUR;\n}",
    "<StreetCodes: 0x7c1db4e0, objectId: EVYUUWzTB7, localId: (null)> {\n    City = BLOEMFONTEIN;\n    StreetCode = 9301;\n    Suburb = AANDRUS;

This returns all the objects in the class witch is added into the array . How do I use this ? Because I just want the City Coulomb objects.

Please help or provide me with some sample code

Rog
  • 16,650
  • 9
  • 48
  • 73

1 Answers1

0

Use PFQuery's selectKeys will limit the query to only retrieving your city data:

[query selectKeys:@[@"City"]];

I think that's not what you want though. You need to run the array of returned objects plucking the City from them:

if (!error)
{
    NSMutableArray* array = [NSMutableArray arrayWithCapacity:objects.count]; // make an array to hold the cities
    for(PFObject* obj in objects) {
        [array addObject:[obj objectForKey:"@City"]];
    }
// etc.
Rog
  • 16,650
  • 9
  • 48
  • 73
  • Thank you for your answer ,I have been struggling with this for quite some time :). – Errol Liebenberg Oct 24 '14 at 09:34
  • hey i know i need to ask another question but i don't have enough reputation points to ask another question for 4 more days. i need to know how to use a searchbar in IOS8 . the searchDisplayController is depricated in IOS8 . i need to know how to search through an string array. – Errol Liebenberg Oct 24 '14 at 13:04
  • http://stackoverflow.com/questions/25826332/searchdispalycontroller-deprecated-ios-8 – Rog Oct 24 '14 at 15:03
  • Thanx Roger , could you update your answer to index the results , say for instance getting all the objects in the City coulomb – Errol Liebenberg Oct 28 '14 at 08:41
  • starting with the letter A – Errol Liebenberg Oct 28 '14 at 08:41
  • That's probably a different question. Have a look at this: http://stackoverflow.com/questions/8303523/sorting-an-nsarray-of-strings-not-string-based – Rog Oct 28 '14 at 08:48