Comments (4)
This is already supported. I'll update the documentation ASAP. Meantime take a look at:
- (void)test_returns_component_from_factory_component
{
Sword* sword = [_componentFactory componentForKey:@"blueSword"];
assertThat([sword description], equalTo(@"A bright blue sword with orange pom-poms at the hilt."));
}
Which in the block style, is satisfied like so:
- (id)swordFactory
{
return [TyphoonDefinition withClass:[SwordFactory class]];
} - (id)blueSword
{
return [TyphoonDefinition withClass:[Sword class] initialization:^(TyphoonInitializer* initializer)
{
initializer.selector = @selector(swordWithSpecification:);
[initializer injectParameterNamed:@"specification" withValueAsText:@"blue" requiredTypeOrNil:[NSString class]];
} properties:^(TyphoonDefinition* definition)
{
//TODO: Fix this
definition.factoryComponent = @"swordFactory";
}];
}
Ahhhhhhh. . . .. But you've just pointed out a TODO, that needs doing. You should be able to say fdefinition.factoryComponent = [self swordFactory] . . . .(currently it is the selector name in string form).
Will fix this today.
On Mar 3, 2013, at 1:47 AM, José González [email protected] wrote:
I was trying to create a Core Data stack using Typhoon and faced the following problem: I had to create the managed object model injecting the URL of the model in the initializer. The URL of the model is typically constructed this way:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CoreDataTest" withExtension:@"momd"];
As far as I know (correct me if I'm wrong) there is no way to create / inject such an object using Typhoon. I could build the main bundle object using Typhoon, but then I have no way of invoking a method on that object to get another object that gets injected in an additional object.I think the general problem to be solved is to add support for factories: in fact the main bundle is a URL factory, using the method shown above. So maybe we could add something like this to Typhoon:
return [TyphoonDefinition withFactory:[self mainBundle] creator:^(TyphoonCreator *creator) {
creator.selector = @selector(URLForResource:withExtension:);
[creator injectParameterAt:0 withValueAsText:@"CoreDataTest" requiredTypeOrNil:[NSString class]];
[creator injectParameterAt:1 withValueAsText:@"momd" requiredTypeOrNil:[NSString class]];
}];
I've noticed I can have a workaround for this problem using type converters, creating a converter that converts the string "CoreDataTest.momd" to the required NSURL, but this would prevent the creation of a "natural" type converter from strings to NSURLs, as Typhoon only supports a converter for a given type.What do you think? Am I missing anything?
—
Reply to this email directly or view it on GitHub.
from typhoon.
As of 1.1.2, you can now wire the factory with:
definition.factory = [self swordFactory];
from typhoon.
Updated the docs, but they need some more attention.
from typhoon.
Great!!! Thanks a lot!
from typhoon.
Related Issues (20)
- Invalid shift exponent in `calculateHash` HOT 4
- Plist Integration in Ios App Extensions
- Not compiled Xcode 9.3 HOT 2
- Flash back crash at startup HOT 1
- Carthage error 65 HOT 4
- Unable to compile after migrating from 3.5.1 to 4.0.5 HOT 5
- Resolve-by-type for ViewController using storyboard HOT 8
- TyphoonDefinition.withClass + classOrProtocolForAutoInjection => Making both work together HOT 1
- PodSpec 4.0.6 HOT 1
- Circular reference level depth HOT 8
- Multiple instances injected into view controller when using storyboard reference HOT 2
- Not all test are run on Travis, example app exception HOT 1
- TyphoonDefinition withConfigName:bundle: does not behave as expected when running tests
- TyphoonStoryboard swift not working HOT 1
- ios 13 Beta crash HOT 2
- cannot run tests HOT 1
- Insecure functions (malloc and memcpy) are used HOT 3
- Injecting a simple object through modularized assembly causes crash
- Framework target HOT 3
- How to get an instance from Typhoon? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typhoon.