Skip to content

Instantly share code, notes, and snippets.

@mmackh
Created March 23, 2014 10:15
Show Gist options
  • Save mmackh/9721136 to your computer and use it in GitHub Desktop.
Save mmackh/9721136 to your computer and use it in GitHub Desktop.
//
// PCMutableDirectory.h
// SmartOrderKit
//
// Created by Maximilian Mackh on 23/03/14.
// Copyright (c) 2014 Professional Consulting & Trading GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PCMutableDirectory : NSObject
+ (instancetype)directory;
- (NSUInteger)indexOfObject:(id)anObject;
- (id)objectAtIndex:(NSUInteger)index;
- (id)objectForKey:(id)key;
- (void)addObject:(id)anObject forKey:(id)key;
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index forKey:(id)key;
- (void)removeObjectAtIndex:(NSUInteger)index forKey:(id)key;
- (void)removeAllObjects;
- (id)firstObject;
- (id)lastObject;
- (NSUInteger)count;
- (NSArray *)allObjects;
@end
//
// PCMutableDirectory.m
// SmartOrderKit
//
// Created by Maximilian Mackh on 23/03/14.
// Copyright (c) 2014 Professional Consulting & Trading GmbH. All rights reserved.
//
#import "PCMutableDirectory.h"
@implementation PCMutableDirectory
{
NSMutableArray *_arrayMutable;
NSMutableDictionary *_dictionaryMutable;
}
#pragma mark -
#pragma mark Init
+ (instancetype)directory
{
return [PCMutableDirectory new];
}
- (id)init
{
self = [super init];
if (!self) return nil;
_arrayMutable = [NSMutableArray new];
_dictionaryMutable = [NSMutableDictionary new];
return self;
}
#pragma mark -
#pragma mark Implementation
- (NSUInteger)indexOfObject:(id)anObject
{
return [_arrayMutable indexOfObject:anObject];
}
- (id)objectAtIndex:(NSUInteger)index
{
return [_arrayMutable objectAtIndex:index];
}
- (id)objectForKey:(id)key
{
return _dictionaryMutable[key];
}
- (void)addObject:(id)anObject forKey:(id)key
{
[_arrayMutable addObject:anObject];
_dictionaryMutable[key] = anObject;
}
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index forKey:(id)key
{
[_arrayMutable insertObject:anObject atIndex:index];
_dictionaryMutable[key] = anObject;
}
- (void)removeObjectAtIndex:(NSUInteger)index forKey:(id)key
{
[_arrayMutable removeObjectAtIndex:index];
[_dictionaryMutable removeObjectForKey:key];
}
- (void)removeAllObjects
{
[_arrayMutable removeAllObjects];
[_dictionaryMutable removeAllObjects];
}
- (id)firstObject
{
return [_arrayMutable firstObject];
}
- (id)lastObject
{
return [_arrayMutable lastObject];
}
- (NSUInteger)count
{
return [_arrayMutable count];
}
- (NSArray *)allObjects
{
return _arrayMutable;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment