Skip to content

Commit 975cd9e

Browse files
committed
Merge branch 'Version-2.1'
2 parents 5871942 + 6e01784 commit 975cd9e

14 files changed

Lines changed: 245 additions & 284 deletions

File tree

TypeExtensions.xcodeproj/project.pbxproj

Lines changed: 78 additions & 66 deletions
Large diffs are not rendered by default.

TypeExtensions/Collection Extensions/NSDictionary+entrySet.m

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,18 @@ @implementation __NSDictionaryEntry
3737

3838
+ (instancetype)dictionaryEntryWithKey:(id<NSObject>)key forDictionary:(NSDictionary *)dictionary
3939
{
40-
return [[[self alloc] initWithKey:key forDictionary:dictionary] autorelease];
40+
return [[self alloc] initWithKey:key forDictionary:dictionary];
4141
}
4242

4343
- (id)initWithKey:(id<NSObject>)key forDictionary:(NSDictionary *)dictionary
4444
{
4545
if (self = [super init]) {
46-
_key = [key retain];
47-
_object = [dictionary[key] retain];
46+
_key = key;
47+
_object = dictionary[key];
4848
}
4949
return self;
5050
}
5151

52-
- (void)dealloc
53-
{
54-
[_key release];
55-
[_object release];
56-
[super dealloc];
57-
}
5852

5953
- (NSString *)description
6054
{

TypeExtensions/Design Pattern Extensions/NSObject+abstractProtocolConformer.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@
1515
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
1616
@implementation NSObject (abstractProtocolConformer)
1717

18+
1819
- (void)doesNotRecognizeSelector:(SEL)aSelector
1920
{
20-
unsigned int count = 0;
21-
Protocol ** protocols = class_copyProtocolList([self class], &count);
22-
for (unsigned int i = 0; i < count; i++)
23-
if (!isNullMethodDescription([[self class] methodDescriptionForSelector:aSelector inProtocol:protocols[i]]))
24-
@throw [[self class] _subclassImplementationExceptionFromMethod:aSelector isClassMethod:NO];
21+
Class class = self.class;
22+
23+
do {
24+
unsigned int count = 0, i;
25+
Protocol * __unsafe_unretained * list = class_copyProtocolList(class, &count);
26+
27+
for (i = 0; i < count; i++)
28+
if (!isNullMethodDescription([class methodDescriptionForSelector:aSelector inProtocol:list[i]]))
29+
goto throw;
30+
31+
free(list);
32+
} while ((class = class.superclass));
33+
2534
__supersInvoke(aSelector);
35+
36+
throw:
37+
@throw [[self class] _subclassImplementationExceptionFromMethod:aSelector isClassMethod:NO];
2638
}
2739

2840
@end

TypeExtensions/Design Pattern Extensions/NSObject_Singleton.m

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
#import "NSObject_Singleton.h"
1010

11+
#import "NSObject+associatedObject.h"
12+
13+
#define kSingletonKey "com.firelizzard.TypeExtensions.Misc.Singleton.key"
14+
1115
@implementation NSObject_Singleton
1216

1317
+ (id)sharedInstance
1418
{
15-
return [[super allocWithZone:NULL] init];
19+
id shared = [self associatedObjectForKey:kSingletonKey];
20+
21+
if (!shared)
22+
[self setAssociatedObject:(shared = [[super allocWithZone:NULL] init]) forKey:kSingletonKey];
23+
24+
return shared;
1625
}
1726

1827
+ (id)allocWithZone:(NSZone *)zone
@@ -24,19 +33,4 @@ - (id)copyWithZone:(NSZone *)zone {
2433
return self;
2534
}
2635

27-
- (id)retain
28-
{
29-
return self;
30-
}
31-
32-
- (id)autorelease
33-
{
34-
return self;
35-
}
36-
37-
- (oneway void)release
38-
{
39-
// don't release
40-
}
41-
4236
@end

TypeExtensions/KVC Extensions/NSObject_KVCArrayForwarding.m

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ @implementation NSObject_KVCArrayForwarding {
2525
- (id)initWithTarget:(id)theTarget keyPath:(NSString *)theKeyPath isMutable:(BOOL)isMutable
2626
{
2727
if (self = [super init]) {
28-
target = [theTarget retain];
29-
keyPath = [theKeyPath retain];
28+
target = theTarget;
29+
keyPath = theKeyPath;
3030
NSString * KeyPath = keyPath.capitalizedString;
3131

3232
Class class = [self class];
@@ -41,10 +41,10 @@ - (id)initWithTarget:(id)theTarget keyPath:(NSString *)theKeyPath isMutable:(BOO
4141
if (subclass == nil)
4242
return nil;
4343

44-
class_addMethod(subclass,
45-
@selector(dealloc),
46-
[class instanceMethodForSelector:@selector(dealloc)],
47-
"v@:");
44+
// class_addMethod(subclass,
45+
// @selector(dealloc),
46+
// [class instanceMethodForSelector:@selector(dealloc)],
47+
// "v@:");
4848

4949
class_addMethod(subclass,
5050
NSSelectorFromString([NSString stringWithFormat:@"countOf%@", KeyPath]),
@@ -105,13 +105,6 @@ - (id)initWithTarget:(id)theTarget keyPath:(NSString *)theKeyPath isMutable:(BOO
105105
return self;
106106
}
107107

108-
- (void)dealloc
109-
{
110-
[target release];
111-
[keyPath release];
112-
113-
[super dealloc];
114-
}
115108

116109
- (NSArray *)arrayProperty
117110
{
@@ -144,7 +137,7 @@ - (NSArray *)arrayObjectsAtIndexes:(NSIndexSet *)indexes
144137
return [self.arrayProperty objectsAtIndexes:indexes];
145138
}
146139

147-
- (void)getArrayObjects:(id *)buffer range:(NSRange)inRange
140+
- (void)getArrayObjects:(__unsafe_unretained id *)buffer range:(NSRange)inRange
148141
{
149142
[self.arrayProperty getObjects:buffer range:inRange];
150143
}

TypeExtensions/KVC Extensions/NSObject_KVCUndefined.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ - (void)dealloc
2929
[_internal_set unlock];
3030
[_internal_get unlock];
3131

32-
[undefined release];
33-
[_internal_set release];
34-
[_internal_get release];
35-
[super dealloc];
3632
}
3733

3834
- (NSArray *)redefinedKeys

TypeExtensions/Other Extensions/Misc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
#import "NSObject+associatedObject.h"
1010
#import "NSObject+invocationForSelector.h"
11-
#import "NSObject+invokeSafely.h"
11+
#import "NSObject+invokeSafely.h"
12+
#import "NSObject_Singleton.h"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// TXZeroingWeakProxy.h
3+
// TypeExtensions
4+
//
5+
// Created by Ethan Reesor on 1/21/14.
6+
// Copyright (c) 2014 Lens Flare. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface TXWeakProxy : NSProxy
12+
13+
+ (instancetype)proxyWithTarget:(NSObject *)target;
14+
- (id)initWithTarget:(NSObject *)target;
15+
16+
@property (readonly, weak) NSObject * target;
17+
@property (unsafe_unretained, readonly) Class targetClass;
18+
19+
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// TXZeroingWeakProxy.m
3+
// TypeExtensions
4+
//
5+
// Created by Ethan Reesor on 1/21/14.
6+
// Copyright (c) 2014 Lens Flare. All rights reserved.
7+
//
8+
9+
#import "TXWeakProxy.h"
10+
11+
@implementation TXWeakProxy
12+
13+
+ (instancetype)proxyWithTarget:(NSObject *)target
14+
{
15+
return [[self alloc] initWithTarget:target];
16+
}
17+
18+
- (id)initWithTarget:(NSObject *)target
19+
{
20+
// if (!(self = [super init]))
21+
// return nil;
22+
23+
_target = target;
24+
_targetClass = target.class;
25+
26+
return self;
27+
}
28+
29+
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
30+
{
31+
return [self.targetClass methodSignatureForSelector:sel];
32+
}
33+
34+
- (void)forwardInvocation:(NSInvocation *)invocation
35+
{
36+
[invocation invokeWithTarget:self.target];
37+
}
38+
39+
@end

TypeExtensions/Protocol Extensions/NSObject_ProtocolConformer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@interface NSObject_ProtocolConformer : NSObject
1212

13-
@property (readonly) Protocol * protocol;
13+
@property (unsafe_unretained, readonly) Protocol * protocol;
1414

1515
- (id)initWithProtocol:(Protocol *)protocol;
1616

0 commit comments

Comments
 (0)