Skip to content

Instantly share code, notes, and snippets.

@alexruperez
Created May 10, 2013 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexruperez/5553006 to your computer and use it in GitHub Desktop.
Save alexruperez/5553006 to your computer and use it in GitHub Desktop.
How to get all keys starting with a common NSString in a NSDictionary
//
// NSDictionary+AllKeysStartingWith.h
//
// Copyright (c) 2013 alexruperez.
//
#import <Foundation/Foundation.h>
@interface NSDictionary (AllKeysStartingWith)
- (NSArray*)allKeysStartingWith:(NSString*)onset;
@end
//
// NSDictionary+AllKeysStartingWith.m
//
// Copyright (c) 2013 alexruperez.
//
#import "NSDictionary+AllKeysStartingWith.h"
@implementation NSDictionary (AllKeysStartingWith)
- (NSArray*)allKeysStartingWith:(NSString*)onset
{
return [[self allKeys] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF BEGINSWITH[cd] %@", onset]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment