ios - How to restructure array of objects -


this question has answer here:

i'm querying object of type nsarray called messages backend on parse.com looks this:

 self.messages = ( "<lean: 0x7fcf98665140, objectid: vgle1uj5ki, localid: (null)> {\n    messagebody = jj;\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424991590106.210938\";\n}", "<lean: 0x7fcf98667940, objectid: rgbfybmklu, localid: (null)> {\n    messagebody = \"test 3 ian\";\n    recipientid = xvvxetqjph;\n    senderid = hoy7ujlzoh;\n    timestamp = \"1424631667110.638184\";\n}", "<lean: 0x7fcf98667f30, objectid: hb5uhwsysu, localid: (null)> {\n    messagebody = \"test 2 user1\";\n    recipientid = xvvxetqjph;\n    senderid = vqzxwbdnal;\n    timestamp = \"1424630904935.162109\";\n}", "<lean: 0x7fcf986685b0, objectid: doe2b9oq5b, localid: (null)> {\n    messagebody = \"test 1\";\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424630808309.478027\";\n}" ) 

so array of dictionary objects. how reformat normal array of dictionaries looks this:

self.messages = ( "{\n objectid: vgle1uj5ki;\n    messagebody = jj;\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424991590106.210938\";\n}", "{\n objectid: rgbfybmklu;\n    messagebody = \"test 3 ian\";\n    recipientid = xvvxetqjph;\n    senderid = hoy7ujlzoh;\n    timestamp = \"1424631667110.638184\";\n}", "{\n objectid: hb5uhwsysu;\n    messagebody = \"test 2 user1\";\n    recipientid = xvvxetqjph;\n    senderid = vqzxwbdnal;\n    timestamp = \"1424630904935.162109\";\n}", "{\n objectid: doe2b9oq5b;\n    messagebody = \"test 1\";\n    recipientid = xvvxetqjph;\n    senderid = xvvxetqjph;\n    timestamp = \"1424630808309.478027\";\n}" ) 

the pfobject returned parse dictionary, insofar responds allkeys , objectforkey: , setobject:forkey:, , on. i've seen several questioners on confused way pfobject implements description , therefore how prints on console, making less dictionary perhaps should.

anyway, if reason 1 must have nsarray of nsdictionaries, rather nsarray of dictionary-like objects, employ code this:

- (nsdictionary *)dictionaryfrompfobject:(pfobject *)pfobject {     nsmutabledictionary *dictionary = [nsmutabledictionary dictionary];     (nsstring *key in [pfobject allkeys]) {         dictionary[key] = [pfobject objectforkey:key];     }     return dictionary; } 

... , call find completion block this:

[query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {     if (!error) {         nsmutablearray *array = [nsmutablearray array];         (pfobject *pfobject in objects) {             [array addobject:[self dictionaryfrompfobject:pfobject]];         }     } }]; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -