1

I'm using the Quickblox API to create group chats, which requires UserID's to be sent to methods using the following format:

NSArray *usersIDs = @[@(55), @(678), @(22)];

This array outputs to the log as such:

Correct Format: (
        55,
        678,
        22
)

In my app, I'm filling the array of User ID's to an NSMutableArray, as such:

[holderArray addObject:[users valueForKey:@"ID"]]

Which outputs to the log like this (which, when I send to the method, isn't working):

My Array: (
        (
        55
    ),
        (
        678
    ), (
        22
    ),
)

Can someone please explain what I'm doing wrong with the holderArray, and how I can get the objects to add in the correct format?

EDIT:

Here is the log output of the users NSArray:

users: (
    "
  [QBUUser]:
  ID:55
  created at:2015-08-27 19:33:24 +0000
  updated at:2015-08-27 19:33:24 +0000
  externalUserID:0
  blobID:0
  facebookID:(null)
  twitterID:(null)
  full name:(null)
  email:(null)
  login:3065555555
  phone:(null)
  tags:(null)
  lastRequestAt:2015-08-29 22:49:34 +0000
  customData:(null)
  website:(null)"
)
7
  • 1
    Well it looks like the type of [users valueForKey:@"ID"] is NSArray. Only you can confirm. Commented Aug 31, 2015 at 18:05
  • why are you using valueForKey? Cant you do something simple like [holderArray addObject:[users objectAtIndex:0]]; ? Commented Aug 31, 2015 at 18:05
  • @T_77 He could be using KVC or it could be a dictionary. Either way, objectAtIndex: will not work. Commented Aug 31, 2015 at 18:06
  • @trojanfoe: yes, users is an NSArray. holdersArray is an NSMutableArray Commented Aug 31, 2015 at 18:10
  • @AdamG An NSArray of what? Dictionaries? Commented Aug 31, 2015 at 18:12

1 Answer 1

3

There is nothing wrong with passing an NSMutableArray, given that it's a subclass of NSArray, the issue is with whatever [users valueForKey:@"ID"] returns, as it looks like an NSArray itself.

From the follow-up comments it looks like it's an NSArray of NSDictionary objects, so users valueForKey: will return all the IDs in the dictionaries. If that's true then just add them to holderArray using addObjectsFromArray:

NSArray *idents = [users valueForKey:@"ID"];
[holderArray addObjectsFromArray:idents];
Sign up to request clarification or add additional context in comments.

2 Comments

actually, using the code above I'm getting an error: expected method to read dictionary element not found on object of type nsarray
@AdamG Yes; your original use of valueForKey: was correct. Fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.