Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

equivalent to @Named injections #66

Open
doug-w opened this issue Feb 9, 2014 · 5 comments
Open

equivalent to @Named injections #66

doug-w opened this issue Feb 9, 2014 · 5 comments

Comments

@doug-w
Copy link

doug-w commented Feb 9, 2014

It would be interesting if a module could add an NSDictionary to an injector and have a new macro that maps keys in that dictionary to properties.

Something like:

@interface MyModule : JSObjectionModule
@end

@implementation MyModule
-(void) configure
{
    [self bindNames:@{@"NamedProperty" : @"This will be a named Property"}];
}
@end

@interface MyObject
@property (weak, nonatomic) NSString* myProperty;
@end

@implementation
objection_requires_names(@{@"NamedProperty" : @"myProperty"})
@end

While not needed it would be nice to have a convience method that would load a plist like that.

@jdewind
Copy link
Contributor

jdewind commented Mar 3, 2014

Interesting idea. You can statically declare NSDictionary data structures? I thought NSString's were still the only place where that was supported.

@doug-w
Copy link
Author

doug-w commented Mar 4, 2014

Objective-C has had object literals since mid 2012 (Clang 4, XCode 4.4, not
sure if gcc ever got it.) @{key:value} NSDictionaries, @[obj2, obj2]
NSArrays, @yES BOOLs, @(2) autoboxing integers, @(nullTerminatedCString)
autoboxed C String to NSString etc..

As for the @nAmed, I keep meaning to play with it, I think I'd like to
separate out the equivalent of properties vs named injected it'd be nice to
support both so that you could have something like:

@Property (weak, nonatomic) FileIOType* configFile; // Gets a singleton
FileIOType that's bound to the config file
@Property (strong, nonatomic) FileIOType* writerFile; // Gets an instance
of a FileIOType

objection_requires_names(@{"FileIO.configFile": @"configFile"}); which
internally would be binding the key to a provider.

If I get the time I may float a prototype for feedback.

On Mon, Mar 3, 2014 at 8:00 AM, Justin DeWind [email protected]:

Interesting idea. You can statically declare NSDictionary data structures?
I thought NSString's were still the only place where that was supported.


Reply to this email directly or view it on GitHubhttps://github.com//issues/66#issuecomment-36524229
.

@jdewind
Copy link
Contributor

jdewind commented Mar 4, 2014

I understand that it has had literals. But my understanding is that they can not be used statically.

@jdewind
Copy link
Contributor

jdewind commented Mar 4, 2014

Actually, concern about the structured being available statically is irrelevant. They are passed to a macro that generates a selector. The context would never be static.

@sethew
Copy link
Contributor

sethew commented Mar 8, 2014

A dictionary can be passed to a macro, but the syntax is a little unusual, as it requires double parentheses:

objection_requires_names((@{@"LeftHeadlight":@"leftHeadlight", @"RightHeadlight":@"rightHeadlight"}))

I have written an implementation of named bindings. It does not handle config files, but it will allow for separate bindings for dependencies of the same class or protocol. I'll submit a pull request, but I'd appreciate any feedback before accepting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants