Reputation: 2439
When I NSLog my NSMutableArray, what I get is the following
{ ABSNFGH True,
FDGJDKG False
GFKFLDL True
PDHJHN True
FHKDMD True
DSHDMD False )
The problem is that, I am not creating this array. But I want to store each entry(e.g. ABSNFGH) in a string and its corresponding status in a bool inside a for loop . How can I do this?
Upvotes: 0
Views: 229
Reputation: 19469
Suppose we name your array as yourArray
yourArray -> { ABSNFGH True,
FDGJDKG False,
GFKFLDL True,
PDHJHN True,
FHKDMD True,
DSHDMD False }
You need to add this loop:
for(int i = 0; i<[yourArray count];i++)
{
NSArray *array = [[yourArray objectAtIndex:i] componentsSeperatedByString:@" "];
if([array count]>1)
{
NSString *stringValue = [array objectAtIndex:0];
BOOL val = [[array objectAtIndex:1] boolValue];
}
}
I think this should work. I have not tried implementing it personally, but may be this would work.
EDIT:
yourArray should ideally be like this:
(
{
stringVal = 'ABSNFGH'
boolVal = True
},
{
stringVal = 'FDGJDKG'
boolVal = False
},
{
stringVal = 'GFKFLDL'
boolVal = True
}
)
Refer to this link. Here you just need to replace object
with a NSDictionary
and you are done.
Making an array of Objects in Objective-C.
Here I have modified ennuikiller's answer from that link, to make you understand for your case:
@interface Controller
NSMutableArray *yourArray;
@end
@implementation Controller
-(void) viewDidLoad {
................
NSMutableArray *yourArray = [NSMutableArray initWithCapacity:40];
}
-(IBAction)doSomeWork
{
NSDictionary *object = [[NSDictionary alloc] init];
[object setValue:@"ASDFG" forKey:@"stringVal"];
[object setBool:False forKey:@"boolVal"];
[yourArray addObject:object];
}
@end
Hope this helps.
Upvotes: 1