-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSArray+Primitive.m
85 lines (65 loc) · 2.07 KB
/
NSArray+Primitive.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Copyright (c) 2012 Norman Basham
// http://www.apache.org/licenses/LICENSE-2.0
//
#import "NSArray+Primitive.h"
@implementation NSArray(Primitive)
-(BOOL)boolAtIndex:(NSUInteger)index {
NSNumber* n = [self objectAtIndex:index];
BOOL b = [n boolValue];
return b;
}
-(char)charAtIndex:(NSUInteger)index {
NSNumber* n = [self objectAtIndex:index];
char c = [n charValue];
return c;
}
-(int)intAtIndex:(NSUInteger)index {
NSNumber* n = [self objectAtIndex:index];
int i = [n intValue];
return i;
}
-(float)floatAtIndex:(NSUInteger)index {
NSNumber* n = [self objectAtIndex:index];
float i = [n floatValue];
return i;
}
@end
@implementation NSMutableArray(Primitive)
-(void)addBool:(BOOL)b {
[self addObject:[NSNumber numberWithBool:b]];
}
-(void)insertBool:(BOOL)b atIndex:(NSUInteger)index {
[self insertObject:[NSNumber numberWithBool:b] atIndex:index];
}
-(void)replaceBoolAtIndex:(NSUInteger)index withBool:(BOOL)b {
[self replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:b]];
}
-(void)addChar:(char)c {
[self addObject:[NSNumber numberWithChar:c]];
}
-(void)insertChar:(char)c atIndex:(NSUInteger)index {
[self insertObject:[NSNumber numberWithChar:c] atIndex:index];
}
-(void)replaceCharAtIndex:(NSUInteger)index withChar:(char)c {
[self replaceObjectAtIndex:index withObject:[NSNumber numberWithChar:c]];
}
-(void)addInt:(int)i {
[self addObject:[NSNumber numberWithInt:i]];
}
-(void)insertInt:(int)i atIndex:(NSUInteger)index {
[self insertObject:[NSNumber numberWithInt:i] atIndex:index];
}
-(void)replaceIntAtIndex:(NSUInteger)index withInt:(int)i {
[self replaceObjectAtIndex:index withObject:[NSNumber numberWithInt:i]];
}
-(void)addFloat:(float)f {
[self addObject:[NSNumber numberWithFloat:f]];
}
-(void)insertFloat:(float)f atIndex:(NSUInteger)index {
[self insertObject:[NSNumber numberWithFloat:f] atIndex:index];
}
-(void)replaceFloatAtIndex:(NSUInteger)index withFloat:(float)f {
[self replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:f]];
}
@end