-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// RCOFactory.h | ||
// Racoon | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface RCOFactory : NSObject | ||
|
||
- (void)configureWithAssembly:(id)assembly; | ||
- (id)componentForType:(Class)klass; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// RCOFactory.m | ||
// Racoon | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import "RCOFactory.h" | ||
|
||
#import "RCOSelectorCache.h" | ||
|
||
@interface RCOFactory () | ||
|
||
@property (nonatomic, strong) id assembly; | ||
@property (nonatomic, strong) RCOSelectorCache *selectorCache; | ||
|
||
@end | ||
|
||
@implementation RCOFactory | ||
|
||
#pragma mark - NSObject | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
_selectorCache = [[RCOSelectorCache alloc] init]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - RCOFactory | ||
|
||
- (void)configureWithAssembly:(id)assembly | ||
{ | ||
self.assembly = assembly; | ||
} | ||
|
||
- (id)componentForType:(Class)klass | ||
{ | ||
SEL selector = [self selectorForType:klass]; | ||
|
||
if ([(NSObject *)self.assembly respondsToSelector:selector]) { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | ||
return [(NSObject *)self.assembly performSelector:selector withObject:nil]; | ||
#pragma clang diagnostic pop | ||
} else { | ||
[NSException raise:NSInvalidArgumentException format:@"The assembly %@ is not able to provide a component of type %@", self.assembly, klass]; | ||
return nil; | ||
} | ||
} | ||
|
||
#pragma mark - RCOFactory | ||
|
||
- (SEL)selectorForType:(Class)klass | ||
{ | ||
SEL selector = [self.selectorCache selectorForType:klass]; | ||
if (selector == RCOSelectorCacheSelectorNotFound) { | ||
NSString *selectorString = [NSString stringWithFormat:@"componentForType%@", NSStringFromClass(klass)]; | ||
selector = NSSelectorFromString(selectorString); | ||
|
||
[self.selectorCache setSelector:selector forType:klass]; | ||
} | ||
|
||
return selector; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// RCOSelectorCache.h | ||
// Racoon | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
extern const SEL RCOSelectorCacheSelectorNotFound; | ||
|
||
@interface RCOSelectorCache : NSObject | ||
|
||
- (SEL)selectorForType:(Class)key; | ||
- (void)setSelector:(SEL)selector forType:(Class)key; | ||
- (void)evictCachedSelectors; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// RCOSelectorCache.m | ||
// Racoon | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import "RCOSelectorCache.h" | ||
|
||
const SEL RCOSelectorCacheSelectorNotFound = 0; | ||
|
||
@implementation RCOSelectorCache { | ||
CFMutableDictionaryRef dictionary; | ||
} | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
if (dictionary) { | ||
CFRelease(dictionary); | ||
} | ||
} | ||
|
||
- (SEL)selectorForType:(Class)key | ||
{ | ||
return (SEL)CFDictionaryGetValue(dictionary, (__bridge const void *)(key)); | ||
} | ||
|
||
- (void)setSelector:(SEL)selector forType:(Class)key | ||
{ | ||
CFDictionarySetValue(dictionary, (__bridge const void *)(key), selector); | ||
} | ||
|
||
- (void)evictCachedSelectors | ||
{ | ||
CFDictionaryRemoveAllValues(dictionary); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// | ||
// Prefix header | ||
// | ||
// The contents of this file are implicitly included at the beginning of every source file. | ||
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Foundation/Foundation.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// Racoon.h | ||
// Racoon | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <Racoon/RCOFactory.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>org.sobik.${PRODUCT_NAME:rfc1034identifier}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// RacoonTests.m | ||
// RacoonTests | ||
// | ||
// Created by Raphael Sobik on 23.08.13. | ||
// Copyright (c) 2013 Raphael Sobik. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@interface RacoonTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation RacoonTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testExample | ||
{ | ||
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* Localized versions of Info.plist keys */ | ||
|