Objective-C - 如何在使用 NSMutableArray 时放置引用 ID?

Objective-C - how to put reference ID while using NSMutableArray?

[randomSelection addObject:renderView]; 上是否有分配自定义 peerID 引用(例如 id:cgiLoC0OdMNtVph3aMZV 或 cxeeeLoC0OdMNtVph3aMZV),以便稍后从某些 random/unsorted UIView 查询?

例如:创建时我有如下情况:

//@property (copy, nonatomic) NSMutableArray *randomSelection;
//UIView *renderView;
//renderView = [[UIView alloc] initWithFrame:CGRectMake(padding_x, padding_y, 50, 50)];
NSMutableArray *randomSelection = [[NSMutableArray alloc] init];
[randomSelection addObject:renderView];
//self.randomSelection = randomSelection;

但有些情况下我需要删除一些 UIView 但在那种情况下我只有一些 peerID 引用。我如何在使用 NSMutableArray

时获得一些自定义参考
- (void)callingRemoveMethod:(NSString *)peerID {
  NSLog(@"removed %@", peerID);

  /* instead of objectAtIndex is there a way to query 
   it by any custom references? */

  //UIView *test = [self.randomSelection objectAtIndex:0];
  //test.backgroundColor = [UIColor redColor];  

}
  1. 您可以改用 NSMutableDictionary 并使用您的 ID 作为字典的键。

  2. UIView 有一个标签 属性(一个 int),您可以将其用于此目的,但它不能是任意信息(只是一个int)

编辑:

NSMutableDictionary *jobs = [NSMutableDictionary
                             dictionaryWithDictionary:@{
                                 @"Audi TT" : @"John",
                                 @"Audi Quattro (Black)" : @"Mary",
                                 @"Audi Quattro (Silver)" : @"Bill",
                                 @"Audi A7" : @"Bill"
                             }];
// Transfer an existing job to Mary
[jobs setObject:@"Mary" forKey:@"Audi TT"];
// Finish a job
[jobs removeObjectForKey:@"Audi A7"];
// Add a new job
jobs[@"Audi R8 GT"] = @"Jack";