Skip to content

Commit

Permalink
[android] Fix issue #995
Browse files Browse the repository at this point in the history
NSArray/NSMutableArray/NSDictionary/NSMutableDictionary now can be used with
Objective-C subscripting.

See http://clang.llvm.org/docs/ObjectiveCLiterals.html

Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
  • Loading branch information
dmsck committed Sep 22, 2015
1 parent 17ef786 commit 4154746
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Foundation/NSArray/NSArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
+ arrayWithObjects:(id *)objects count:(NSUInteger)count;

- (NSUInteger)count;
- objectAtIndex:(NSUInteger)index;
- (id)objectAtIndex:(NSUInteger)index;
- (id)objectAtIndexedSubscript:(NSUInteger)index;

- (void)getObjects:(id *)objects;
- (void)getObjects:(id *)objects range:(NSRange)range;
Expand Down
4 changes: 4 additions & 0 deletions Foundation/NSArray/NSArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ -(NSUInteger)count {
return nil;
}

-(id)objectAtIndexedSubscript:(NSUInteger)index {
return [self objectAtIndex:index];
}

-(void)getObjects:(id *)objects {
NSUInteger i,count=[self count];

Expand Down
2 changes: 2 additions & 0 deletions Foundation/NSArray/NSMutableArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- (void)sortUsingDescriptors:(NSArray *)descriptors;
- (void)filterUsingPredicate:(NSPredicate *)predicate;

- (void)setObject:(id)value atIndexedSubscript:(NSUInteger)idx;

@end
3 changes: 3 additions & 0 deletions Foundation/NSArray/NSMutableArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ -(void)replaceObjectAtIndex:(NSUInteger)index withObject:object {
NSInvalidAbstractInvocation();
}

- (void)setObject:(id)value atIndexedSubscript:(NSUInteger)index {
[self replaceObjectAtIndex:index withObject:value];
}

-(void)replaceObjectsInRange:(NSRange)range
withObjectsFromArray:(NSArray *)array {
Expand Down
1 change: 1 addition & 0 deletions Foundation/NSDictionary/NSDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
+ dictionaryWithContentsOfURL:(NSURL *)url;

- objectForKey:key;
- (id)objectForKeyedSubscript:(id<NSCopying>)key;
- (NSUInteger)count;
- (NSEnumerator *)keyEnumerator;
- (NSEnumerator *)objectEnumerator;
Expand Down
4 changes: 4 additions & 0 deletions Foundation/NSDictionary/NSDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ -(void)encodeWithCoder:(NSCoder *)coder {
return nil;
}

- (id)objectForKeyedSubscript:(id<NSCopying>)key {
return [self objectForKey:key];
}

-(NSUInteger)count {
NSInvalidAbstractInvocation();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions Foundation/NSDictionary/NSMutableDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- (void)removeAllObjects;
- (void)removeObjectsForKeys:(NSArray *)keys;

- (void)setObject:(id)value forKeyedSubscript:(id<NSCopying>)key;

@end
4 changes: 4 additions & 0 deletions Foundation/NSDictionary/NSMutableDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ -(void)removeObjectsForKeys:(NSArray *)keys {
[self removeObjectForKey:[keys objectAtIndex:count]];
}

- (void)setObject:(id)value forKeyedSubscript:(id<NSCopying>)key {
[self setObject:value forKey:key];
}

@end

0 comments on commit 4154746

Please sign in to comment.