如何将字符串添加到 NSArray 的特定索引处?
NSInteger timeNum = time;
NSMutableArray theResultArray = [[NSMutableArray alloc] init];
[theResultArray insertObject:[NSNumber numberWithInt:timeNum] atIndex:rightIndex];
这就是我们将 NSInteger 插入数组的方法。我该如何为 NSString 做到这一点?
NSInteger timeNum = time;
NSMutableArray theResultArray = [[NSMutableArray alloc] init];
[theResultArray insertObject:[NSNumber numberWithInt:timeNum] atIndex:rightIndex];
This is the way we do to insert NSInteger to array. How to i do it for NSString?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这更容易,因为您不必封装整数:
希望有帮助。
It's easier because you don't have to encapsulate the integer:
Hope that helps.
完全相同:
请注意,如果您尝试在不存在的位置插入对象(即,如果 rightIndex > [theResultArray count]),您将收到异常。在上面的示例中,rightIndex 的唯一合法值为 0,因为数组为空。
It's exactly the same:
Be aware that if you try to insert an object in a position that doesn't exist (i.e. if rightIndex > [theResultArray count]), you will get an exception. In the example above, the only legal value for rightIndex is 0 because the array is empty.