Reputation: 265
i have made an array and a dictionary. now i want to put the values of dictionary in to array.. i am very new to objective C so kindly help. "viewcontroller .m"
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
marray = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4", nil];
marray = [[NSMutableArray alloc]initWithObjects:@"6",@"7",@"8",@"9",@"10", nil];
[self displayarray];
[marray release];
mDictionary = [[NSMutableDictionary alloc]init];
[mDictionary setValue:@"sdfsdhfg" forKey:@"firstname"];
[mDictionary setValue:@"kvxv" forKey:@"lastname"];
[self displaydict];
[mDictionary release];
}
-(void)displaydict{
CFShow(mDictionary);
}
-(void)displayarray{
for (int i = 0; i<[marray count]; i++) {
NSLog(@"the array data present at %d index is %@",i,[marray objectAtIndex:i]);
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
Upvotes: 4
Views: 27033
Reputation: 46563
Your question contains so many other questions, I will try to solve few of them related to converting dictionary to array.
Store all keys
NSArray *dictKeys=[dict allKeys];
Store all values
NSArray *dictValues=[dict allValues];
If you want to store both keys and values:
NSArray *keysAndValues=[dictKeys arrayByAddingObjectsFromArray:dictValues];
EDIT:
As you require NSMutableArray, you can use :
NSMutableArray *dictAllKeys=[NSMutableArray arrayWithArray:[dict allKeys]];
NSMutableArray *dictAllValues=[NSMutableArray arrayWithArray:[dict allValues]];
NSMutableArray *keysAndValues=[NSMutableArray arrayWithArray:[dictAllKeys arrayByAddingObjectsFromArray:dictAllValues]];
Upvotes: 9
Reputation: 1088
for (NSDictionary *dictionary in arrayname)
{
NSMutableArray *array = [dictionary objectForKey:@"writeKey"];
}
This might help you
Upvotes: 3
Reputation: 328
If you want to access the values of Dictionary, use particular key for values. For that use the following format.
NSArray *yourarray=[YourDictionary ObjectForKey:@"KEY"];
I hope this will help you.
Upvotes: 0