-1

I need to store both the NSRange object and NSInteger inside the NSMutableDictionary?

Can I do it?

If it is, Could you give me an example?

Girish
  • 4,692
  • 4
  • 35
  • 55
Kirubachari
  • 688
  • 11
  • 27

2 Answers2

4

You can store the NSInteger as NSNumber object.

mutableDictionary[integerKey] = [NSNumber numberWithInteger:integer];

or even better

mutableDictionary[integerKey] = @(integer);

For NSRange, use NSValue object.

mutableDictionary[rangeKey] = [NSValue valueWithRange:range];
Mohannad A. Hassan
  • 1,650
  • 1
  • 13
  • 24
-1

I have used NSString for both NSRange and NSInteger, to remove confusion use this:

NSInteger i = 6;
    NSRange range = NSMakeRange (25, 3);
    NSMutableDictionary *dic =[[NSMutableDictionary alloc] init];
    [dic setObject:NSStringFromRange(range) forKey:@"range"];
    [dic setObject:[NSString stringWithFormat:@"%d",i] forKey:@"integer"];
    //How to get it...
    NSRange range1 =  NSRangeFromString([dic objectForKey:@"range"]) ;
    NSInteger inte = [[dic objectForKey:@"integer"] integerValue];
Prateek Prem
  • 1,544
  • 11
  • 14