i have an array list of custom objects. each object contains a value i need to pull out, claimNO, but is not a unique value, meaning say 5 objects may have the same claimNO.
what i need to do is make an array that only has unique claimNO's. i need to display this in a picker and can't have any repeating claimNO.
my object:
@interface ClaimCenterClaim : NSObject
{
NSNumber *claimID;
NSString *claimNO;
NSNumber *coid;
NSString *eventDates;
}
@property (nonatomic, retain) NSNumber *claimID;
@property (nonatomic, retain) NSString *claimNO;
@property (nonatomic, retain) NSNumber *coid;
@property (nonatomic, retain) NSString *eventDates;
@end
to me, this should work:
NSMutableDictionary *ClaimCenterClaimNOList = [[NSMutableDictionary alloc] init];
int count01 = [sortedClaimList count];
for (int i = 0; i < count01; i++)
{
claimCenterClaim = [sortedClaimList objectAtIndex:i];
if ([ClaimCenterClaimNOList objectForKey:claimCenterClaim.claimID] != claimCenterClaim.claimNO)
{
NSLog(@"entered the bloody loop");
[ClaimCenterClaimNOList setObject:claimCenterClaim.claimNO forKey:claimCenterClaim.claimID];
}
else
NSLog(@"did not add value");
}
but my value for "[ClaimCenterClaimNOList objectForKey:claimCenterClaim.claimID]" is always null untill after the if statement.
if i have a claimID value, can't i just check if that key value in the dictionary already exists, and if it doesn't, add it?
i would like to avoid needing to iterate thru the ClaimCenterClaimNOList dictionary (creates a loop in a loop). but i know the key, can't i just see if that key already exists in the dictionary?
EDIT: incorrect logic
my claimID values are unique, so i was checking my dictionary if a claimID was already added to the dictionary. since claimID is unique, it never found a match. i switched the search around and is now working. here's the correct code:
int count01 = [sortedClaimList count];
for (int i = 0; i < count01; i++)
{
claimCenterClaim = [sortedClaimList objectAtIndex:i];
NSLog(@"lets see before: claimCenterClaim.claimiD: %@ the object: %@",claimCenterClaim.claimID, [ClaimCenterClaimNOList objectForKey:claimCenterClaim.claimID]);
if ([ClaimCenterClaimNOList objectForKey:claimCenterClaim.claimNO] == nil)
{
NSLog(@"not in the dictionary");
[ClaimCenterClaimNOList setObject:claimCenterClaim.claimID forKey:claimCenterClaim.claimNO];
}
else
{
NSLog(@"it works, it is in the dictionary");
}
}