我正在使用Quickblox API创建群聊,这要求将UserID发送到使用以下格式的方法:
NSArray *usersIDs = @[@(55), @(678), @(22)];
该数组将这样输出到日志:
Correct Format: (
55,
678,
22
)
在我的应用中,我将用户ID数组填充到NSMutableArray中,如下所示:
[holderArray addObject:[users valueForKey:@"ID"]]
哪个输出到日志是这样的(当我发送到方法时,它不起作用):
My Array: (
(
55
),
(
678
), (
22
),
)
有人可以解释一下我使用holderArray做错了什么,以及如何使对象以正确的格式添加?
编辑:
这是用户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)"
)
最佳答案
传递NSMutableArray
并没有错,因为它是NSArray
的子类,所以问题在于[users valueForKey:@"ID"]
返回的内容都是什么,因为它看起来像NSArray
本身。
在后续注释中,它看起来像是NSArray
对象的NSDictionary
,因此users valueForKey:
将返回字典中的所有ID。如果是这样,则只需使用holderArray
将它们添加到addObjectsFromArray
中:
NSArray *idents = [users valueForKey:@"ID"];
[holderArray addObjectsFromArray:idents];
关于ios - Objective-C:NSArray与NSMutableArray的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32317123/