Fix 10.7 compatibility and add a window to show an exception log

This commit is contained in:
galad87 committed 2015-08-29 11:41:24 +02:00
1 parent 60b1c60155
commit d1360727ec
13 files changed
+452

No files matched your search

@@ -0,0 +1,4 @@
#include <Foundation/Foundation.h>
@interface NSArray (Subscripting)
@end
@@ -0,0 +1,26 @@
#import "NSArray+Subscripting.h"
#import <objc/runtime.h>
@implementation NSArray (Subscripting)
+ (void)load
{
Class class = [self class];
SEL swizzledSelector = @selector(bnr_objectAtIndexedSubscript:);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
class_addMethod([NSArray class],
@selector(objectAtIndexedSubscript:),
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)
);
}
- (id)bnr_objectAtIndexedSubscript:(NSInteger)index
{
return [self objectAtIndex:index];
}
@end
+12
View File
@@ -0,0 +1,12 @@
//
// NSDictionary+Subscript.h
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDictionary (Subscript)
@end
+34
View File
@@ -0,0 +1,34 @@
//
// NSDictionary+Subscript.m
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#import "NSDictionary+Subscript.h"
#import <objc/runtime.h>
@implementation NSDictionary (Subscript)
+ (void)load
{
Class class = [self class];
SEL swizzledSelector = @selector(dg_objectForKeyedSubscript:);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
class_addMethod([NSDictionary class],
@selector(objectForKeyedSubscript:),
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)
);
}
-(id)dg_objectForKeyedSubscript:(id)key
{
return [self objectForKey:key];
}
@end
+12
View File
@@ -0,0 +1,12 @@
//
// NSMutableArray+Subscript.h
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSMutableArray (Subscript)
@end
+50
View File
@@ -0,0 +1,50 @@
//
// NSMutableArray+Subscript.m
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#if __has_feature(objc_arc)
#import "NSMutableArray+Subscript.h"
@implementation NSMutableArray (Subscript)
+ (void)load
{
Class class = [self class];
SEL swizzledSelector = @selector(dg_setObject:atIndexedSubscript:);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
class_addMethod([NSMutableArray class],
@selector(setObject:atIndexedSubscript:),
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)
);
}
- (void)dg_setObject:(id)anObject atIndexedSubscript:(NSUInteger)index
{
if(anObject == nil)
{
[NSException raise:NSInvalidArgumentException format:@"setObject:atIndexedSubscript does not allow objects to be nil"];
}
if(index > self.count)
{
[NSException raise:NSRangeException format:@"setObject:atIndexedSubscript does not allow the index to be out of array bounds"];
}
if(index == self.count)
{
[self addObject:anObject];
}
else
{
[self replaceObjectAtIndex:index withObject:anObject];
}
}
@end
#endif
+12
View File
@@ -0,0 +1,12 @@
//
// NSMutableDictionary+Subscript.h
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSMutableDictionary (Subscript)
@end
+34
View File
@@ -0,0 +1,34 @@
//
// NSMutableDictionary+Subscript.m
//
//
// Created by Sernin van de Krol on 8/21/12.
// Copyright (c) 2012 Sernin van de Krol. All rights reserved.
//
#import "NSMutableDictionary+Subscript.h"
#import <objc/runtime.h>
@implementation NSMutableDictionary (Subscript)
+ (void)load
{
Class class = [self class];
SEL swizzledSelector = @selector(dg_setObject:forKeyedSubscript:);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
class_addMethod([NSMutableDictionary class],
@selector(setObject:forKeyedSubscript:),
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)
);
}
- (void)dg_setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey
{
[self setObject:object forKey:aKey];
}
@end