[英]Create dictionary from an array of objects using property of object as key for the dictionary?
[英]Short Getting objects from dictionary with key to array
我得到了數組A。它包含帶有NSStrings鍵“ b”的字典。
我需要在新數組中獲取所有NSString。
我不想用多於1個的字符串來實現。 可能嗎?
我需要它,因為我想在其中為鍵“ b”插入對象數組
NSMutableArray *videosStr = [NSMutableArray arrayWithArray: HERE ];
還是最短的方法呢? 我還需要原始排序
嘗試執行此操作以獲取鍵為"b"
所有元素,
NSMutableArray *videosStr = [NSMutableArray arrayWithArray: [dictionayArray valueForKey:@"b"] ];
您可以為其使用鍵值編碼。 以下是示例代碼:
NSDictionary *dict1 = [NSDictionary dictionaryWithObject:@"test1" forKey:@"b"];
NSDictionary *dict2 = [NSDictionary dictionaryWithObject:@"test2" forKey:@"b"];
NSDictionary *dict3 = [NSDictionary dictionaryWithObject:@"test3" forKey:@"b"];
NSArray *arr = @[dict1, dict2, dict3];
NSArray * videosStr =[arr valueForKeyPath:@"b"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.