Skip to content

Commit

Permalink
Merge branch 'Version-2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jan 22, 2014
2 parents 5871942 + 6e01784 commit 975cd9e
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 284 deletions.
144 changes: 78 additions & 66 deletions TypeExtensions.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions TypeExtensions/Collection Extensions/NSDictionary+entrySet.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,18 @@ @implementation __NSDictionaryEntry

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

- (id)initWithKey:(id<NSObject>)key forDictionary:(NSDictionary *)dictionary
{
if (self = [super init]) {
_key = [key retain];
_object = [dictionary[key] retain];
_key = key;
_object = dictionary[key];
}
return self;
}

- (void)dealloc
{
[_key release];
[_object release];
[super dealloc];
}

- (NSString *)description
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
@implementation NSObject (abstractProtocolConformer)


- (void)doesNotRecognizeSelector:(SEL)aSelector
{
unsigned int count = 0;
Protocol ** protocols = class_copyProtocolList([self class], &count);
for (unsigned int i = 0; i < count; i++)
if (!isNullMethodDescription([[self class] methodDescriptionForSelector:aSelector inProtocol:protocols[i]]))
@throw [[self class] _subclassImplementationExceptionFromMethod:aSelector isClassMethod:NO];
Class class = self.class;

do {
unsigned int count = 0, i;
Protocol * __unsafe_unretained * list = class_copyProtocolList(class, &count);

for (i = 0; i < count; i++)
if (!isNullMethodDescription([class methodDescriptionForSelector:aSelector inProtocol:list[i]]))
goto throw;

free(list);
} while ((class = class.superclass));

__supersInvoke(aSelector);

throw:
@throw [[self class] _subclassImplementationExceptionFromMethod:aSelector isClassMethod:NO];
}

@end
26 changes: 10 additions & 16 deletions TypeExtensions/Design Pattern Extensions/NSObject_Singleton.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@

#import "NSObject_Singleton.h"

#import "NSObject+associatedObject.h"

#define kSingletonKey "com.firelizzard.TypeExtensions.Misc.Singleton.key"

@implementation NSObject_Singleton

+ (id)sharedInstance
{
return [[super allocWithZone:NULL] init];
id shared = [self associatedObjectForKey:kSingletonKey];

if (!shared)
[self setAssociatedObject:(shared = [[super allocWithZone:NULL] init]) forKey:kSingletonKey];

return shared;
}

+ (id)allocWithZone:(NSZone *)zone
Expand All @@ -24,19 +33,4 @@ - (id)copyWithZone:(NSZone *)zone {
return self;
}

- (id)retain
{
return self;
}

- (id)autorelease
{
return self;
}

- (oneway void)release
{
// don't release
}

@end
21 changes: 7 additions & 14 deletions TypeExtensions/KVC Extensions/NSObject_KVCArrayForwarding.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ @implementation NSObject_KVCArrayForwarding {
- (id)initWithTarget:(id)theTarget keyPath:(NSString *)theKeyPath isMutable:(BOOL)isMutable
{
if (self = [super init]) {
target = [theTarget retain];
keyPath = [theKeyPath retain];
target = theTarget;
keyPath = theKeyPath;
NSString * KeyPath = keyPath.capitalizedString;

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

class_addMethod(subclass,
@selector(dealloc),
[class instanceMethodForSelector:@selector(dealloc)],
"v@:");
// class_addMethod(subclass,
// @selector(dealloc),
// [class instanceMethodForSelector:@selector(dealloc)],
// "v@:");

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

- (void)dealloc
{
[target release];
[keyPath release];

[super dealloc];
}

- (NSArray *)arrayProperty
{
Expand Down Expand Up @@ -144,7 +137,7 @@ - (NSArray *)arrayObjectsAtIndexes:(NSIndexSet *)indexes
return [self.arrayProperty objectsAtIndexes:indexes];
}

- (void)getArrayObjects:(id *)buffer range:(NSRange)inRange
- (void)getArrayObjects:(__unsafe_unretained id *)buffer range:(NSRange)inRange
{
[self.arrayProperty getObjects:buffer range:inRange];
}
Expand Down
4 changes: 0 additions & 4 deletions TypeExtensions/KVC Extensions/NSObject_KVCUndefined.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ - (void)dealloc
[_internal_set unlock];
[_internal_get unlock];

[undefined release];
[_internal_set release];
[_internal_get release];
[super dealloc];
}

- (NSArray *)redefinedKeys
Expand Down
3 changes: 2 additions & 1 deletion TypeExtensions/Other Extensions/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

#import "NSObject+associatedObject.h"
#import "NSObject+invocationForSelector.h"
#import "NSObject+invokeSafely.h"
#import "NSObject+invokeSafely.h"
#import "NSObject_Singleton.h"
19 changes: 19 additions & 0 deletions TypeExtensions/Other Extensions/TXWeakProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// TXZeroingWeakProxy.h
// TypeExtensions
//
// Created by Ethan Reesor on 1/21/14.
// Copyright (c) 2014 Lens Flare. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface TXWeakProxy : NSProxy

+ (instancetype)proxyWithTarget:(NSObject *)target;
- (id)initWithTarget:(NSObject *)target;

@property (readonly, weak) NSObject * target;
@property (unsafe_unretained, readonly) Class targetClass;

@end
39 changes: 39 additions & 0 deletions TypeExtensions/Other Extensions/TXWeakProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// TXZeroingWeakProxy.m
// TypeExtensions
//
// Created by Ethan Reesor on 1/21/14.
// Copyright (c) 2014 Lens Flare. All rights reserved.
//

#import "TXWeakProxy.h"

@implementation TXWeakProxy

+ (instancetype)proxyWithTarget:(NSObject *)target
{
return [[self alloc] initWithTarget:target];
}

- (id)initWithTarget:(NSObject *)target
{
// if (!(self = [super init]))
// return nil;

_target = target;
_targetClass = target.class;

return self;
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
return [self.targetClass methodSignatureForSelector:sel];
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
[invocation invokeWithTarget:self.target];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface NSObject_ProtocolConformer : NSObject

@property (readonly) Protocol * protocol;
@property (unsafe_unretained, readonly) Protocol * protocol;

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

Expand Down
4 changes: 2 additions & 2 deletions TypeExtensions/TypeExtensions-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0</string>
<string>2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>100</string>
<string>124</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2012 Lens Flare. Some rights reserved, see license.</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion TypeExtensions/Value Extensions/NSData+stringValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @implementation NSData (stringValue)

- (NSString *)stringValue
{
return [[[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding];
}

@end
120 changes: 59 additions & 61 deletions TypeExtensionsTests/TECollectionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#import <XCTest/XCTest.h>
#import <TypeExtensions/Collection.h>
#import <TypeExtensions/NSMutableArray_NonRetaining_Zeroing.h>
#import <TypeExtensions/NSMutableDictionary_NonRetaining_Zeroing.h>

#import "Dummy.h"

Expand All @@ -19,64 +17,64 @@ @interface TECollectionTests : XCTestCase

@implementation TECollectionTests

- (void)testEntrySet
{
NSDictionary * dictionary = @{ @(1) : @"One", @(2) : @"Two" };

NSSet * entries = [dictionary entrySet];

NSMutableSet * test = [NSMutableSet setWithCapacity:dictionary.count];
[test addObject:[NSDictionaryEntrySetEntry dictionaryEntryWithKey:@(1) forDictionary:dictionary]];
[test addObject:[NSDictionaryEntrySetEntry dictionaryEntryWithKey:@(2) forDictionary:dictionary]];

// BUG: for some reason [entries isEqual:test] doesn't work...
for (id obj in test)
if (![entries.allObjects containsObject:obj])
XCTFail(@"Sets are not equal");

for (NSDictionaryEntrySetEntry * entry in entries) {
if ([@(1) isEqual:entry.key]) {
if (![dictionary[@(1)] isEqual:entry.object])
XCTFail(@"Entry set is bad");
} else if ([@(2) isEqual:entry.key]) {
if (![dictionary[@(2)] isEqual:entry.object])
XCTFail(@"Entry set is bad");
}
}
}

- (void)testNonRetainingZeroingArray
{
NSObject * obj = [[Dummy alloc] init];

TXMutableWeakArray * arr = [TXMutableWeakArray array];

[arr addObject:obj];

if (!arr.count)
XCTFail(@"Array does not contain object");

[obj release];

if (arr.count)
XCTFail(@"Array contains object after it's release");
}

- (void)testNonRetainingZeroingDictionary
{
NSObject * obj = [[Dummy alloc] init];

TXMutableWeakDictionary * dict = [TXMutableWeakDictionary dictionary];

dict[@(1)] = obj;

if (!dict.count)
XCTFail(@"Array does not contain object");

[obj release];

if (dict.count)
XCTFail(@"Array contains object after it's release");
}
//- (void)testEntrySet
//{
// NSDictionary * dictionary = @{ @(1) : @"One", @(2) : @"Two" };
//
// NSSet * entries = [dictionary entrySet];
//
// NSMutableSet * test = [NSMutableSet setWithCapacity:dictionary.count];
// [test addObject:[NSDictionaryEntrySetEntry dictionaryEntryWithKey:@(1) forDictionary:dictionary]];
// [test addObject:[NSDictionaryEntrySetEntry dictionaryEntryWithKey:@(2) forDictionary:dictionary]];
//
// // BUG: for some reason [entries isEqual:test] doesn't work...
// for (id obj in test)
// if (![entries.allObjects containsObject:obj])
// XCTFail(@"Sets are not equal");
//
// for (NSDictionaryEntrySetEntry * entry in entries) {
// if ([@(1) isEqual:entry.key]) {
// if (![dictionary[@(1)] isEqual:entry.object])
// XCTFail(@"Entry set is bad");
// } else if ([@(2) isEqual:entry.key]) {
// if (![dictionary[@(2)] isEqual:entry.object])
// XCTFail(@"Entry set is bad");
// }
// }
//}
//
//- (void)testNonRetainingZeroingArray
//{
// NSObject * obj = [[Dummy alloc] init];
//
// TXMutableWeakArray * arr = [TXMutableWeakArray array];
//
// [arr addObject:obj];
//
// if (!arr.count)
// XCTFail(@"Array does not contain object");
//
// [obj release];
//
// if (arr.count)
// XCTFail(@"Array contains object after it's release");
//}
//
//- (void)testNonRetainingZeroingDictionary
//{
// NSObject * obj = [[Dummy alloc] init];
//
// TXMutableWeakDictionary * dict = [TXMutableWeakDictionary dictionary];
//
// dict[@(1)] = obj;
//
// if (!dict.count)
// XCTFail(@"Array does not contain object");
//
// [obj release];
//
// if (dict.count)
// XCTFail(@"Array contains object after it's release");
//}

@end
Loading

0 comments on commit 975cd9e

Please sign in to comment.