appsquickly / typhoon

Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
https://pilgrim.ph
Apache License 2.0
2.7k stars 269 forks source link

TyphoonTypeConverter for array in config #549

Closed ivanyorgov closed 7 years ago

ivanyorgov commented 7 years ago

Hi, I've created a TyphoonTypeConverter for a custom object, I have tested it with a single object injection from the config file, and it is working fine.

<key>singleObject</key>
    <string>CustomObject(object)</string>

Is it currently possible to make it work with an array of objects from the config.

<key>customObjects</key>
    <array>
        <string>CustomObject(object1)</String>
        <string>CustomObject(object2)</String>
        <string>CustomObject(object3)</String>
    </array>

I have tried with no success.

o15a3d4l11s2 commented 7 years ago

+1

alexgarbarev commented 7 years ago

Have you tried to inject TyphoonConfig(@"singleObject"). I think it will inject an NSArray of custom objects. Or not?

ivanyorgov commented 7 years ago

@alexgarbarev For singleObject it works, because it is a single object. It doesn't work for the second case with array of objects in the config.

etolstoy commented 7 years ago

@ivanyorgov This feature is not currently possible. You can use a custom TyphoonTypeConverter for this. See documentation for more info.

E.g. You'd be able to write a TyphoonTypeConverter that can convert this:

<key>MyArray</key>
    <string>CustomArray(object1,object2,object3,object4)</string>

into this:

@[@"object1", @"object2", @"object3", @"object4"]

Does it solve your problem?

ivanyorgov commented 7 years ago

@etolstoy I also thought of this, but in the end came up with another solution. I've created a retriever object to which I inject the configuration, then I use the TypeConverter manually. I inject the retriever object to the controller, and when needed I get the objects.

etolstoy commented 7 years ago

Great! Closing this issue then.