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
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]];
for (NSDictionary *dictionary in arrayname)
{
NSMutableArray *array = [dictionary objectForKey:@"writeKey"];
}
This might help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With