Skip to content

Commit 6a165f5

Browse files
committed
really update readme
1 parent f51dd26 commit 6a165f5

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

README.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
[![Build Status](https://travis-ci.org/Swinject/Swinject-CodeGen.svg?branch=master)](https://travis-ci.org/Swinject/Swinject-CodeGen)
44

5-
I would call it a very elaborated proof of concept, though we use it in production atm.
6-
We are open for every kind of feedback, improvements of the generated code/templates, discussion of the input format etc.
7-
85
## TLDR;
96

10-
We propose a method to get rid of duplicate use of class values and namestrings, by generating explicit functions for registering and resolving.
7+
Swinject-CodeGen provides a method to get rid of duplicate use of class values and namestrings, by generating explicit functions for registering and resolving using Swinject.
118
Doing this, we also can generate typed tuples to use when resolving, thus allowing better documented and less error-prone code.
129

1310
## Installation
14-
15-
We aim to support carthage in the near future
16-
1711
### Cocoapods
1812

1913
Add
@@ -24,24 +18,38 @@ pod 'Swinject-CodeGen', :git => 'https://github.com/Swinject/Swinject-CodeGener
2418

2519
to your podfile.
2620

21+
### Carthage
22+
23+
Add
24+
25+
```
26+
github "Swinject/Swinject-CodeGeneration"
27+
```
28+
29+
to your Cartfile.
30+
2731
## Integration
2832
1. Define your dependencies in a .csv or .yml file (see below and example file)
2933
2. Add a call to generate the code as build script phase:
3034

35+
For Cocoapods:
3136
```Shell
3237
$PODS_ROOT/Swinject-CodeGen/bin/swinject_codegen -i baseInput.csv -o extensions/baseContainerExtension.swift
3338
```
3439

40+
For Carthage:
41+
```Shell
42+
$SRCROOT/Carthage/Checkouts/Swinject-CodeGen/bin/swinject_codegen -i baseInput.csv -o extensions/baseContainerExtension.swift
43+
```
44+
3545
3. Add the generated file (here: `extensions/baseContainerExtension.swift`) to xcode
3646
4. Repeat if you need to support multiple targets/have multiple input files.
3747

3848
The code is then generated at every build run.
3949

4050
## The Issue
4151

42-
We love using swinject for dependency injection.
43-
However, we would like to stay to the DRY principle and really love types.
44-
When using swinject, lots of duplicate definitions appear, whenever we do a
52+
When using Swinject, lots of duplicate definitions appear, whenever we do a
4553

4654
```Swift
4755
container.register(PersonType.self, name: "initializer") { r in
@@ -99,7 +107,15 @@ We decided to use `;` as delimiter instead of `,` to allow the use of tuples as
99107
#### Additional Commands
100108
The ruby parser allows using `//` and `#` for comments.
101109
Empty lines are ignored and can be used for grouping.
102-
`#= <header>` can be used to specify additional headers, e.g. `#ADD_HEADER import KeychainAccess`
110+
111+
`#= <header>` can be used to specify additional lines, e.g. `#= import KeychainAccess`
112+
113+
#### Dictionaries and Arrays as Parameters
114+
When using typed dictionaries or arrays as parameters, use `Array<Type>` instead of `[Type]` and `Dictionary<TypeA, TypeB>` instead of `[TypeA:TypeB]`:
115+
116+
```CSV
117+
PersonType; InjectablePerson; initializer; additionalNames:Array<String>; family:Dictionary<String, String>;
118+
```
103119

104120
### YML
105121

@@ -356,31 +372,18 @@ container.registerAnimalType { (_, name:String) in
356372
let horse1 = container.resolveAnimalType("Spirit")
357373
```
358374

359-
We can provide more examples if desired.
360-
361-
## Integration
362-
363-
The Integration is currently done by calling the following code in a very early (i.e. before compilation) build phase:
364-
```SH
365-
cd ${SRCROOT}/CodeGeneration/
366-
swinject_codegen -i baseInput.csv -o extensions/baseContainerExtension.swift
367-
swinject_codegen -i iosInput.csv -o extensions/iosContainerExtension.swift
368-
swinject_codegen -i tvosInput.csv -o extensions/tvosContainerExtension.swift
369-
```
370-
371-
The resulting extension files are added to xcode and given appropriate target settings.
372-
373375
## Migration
374376
The script also generates migration.sh files (when using the -m switch), which use sed to go through the code and replace simple cases (i.e. no arguments) of resolve and register.
375377
No automatic migration is available for cases with arguments, yet.
376378
Simply call the .sh file from the root of the project and compare the results in a git-GUI.
377379

378380
## Results
379-
We currently use the code generation in a medium-sized app, with a total of ~130 lines of definitions across 3 .csv files (shared definitions, iOS only, tvOS only).
380-
We found our code to become much more convenient to read and write, due to reduced duplication and autocompletion. We also have a much better overview the classes available through dependency injection.
381+
We currently use the code generation in two medium-sized apps across tvOS and iOS.
382+
383+
We found our code to become much more convenient to read and write, due to reduced duplication and autocompletion.
384+
We also have a much better overview the classes available through dependency injection.
381385
Changing some definition immediately leads to information, where an error will occur.
382386
We were able to replace all our occurences of `.resolve(` and `.register(` using the current implementation.
383387

384-
385388
## Contributors
386-
The main contributors for this are [Daniel Dengler](https://github.com/ddengler), [David Kraus](https://github.com/davidkraus) and [Wolfgang Lutz](https://github.com/lutzifer).
389+
The original idea for combining CodeGeneration and Swinject came from [Daniel Dengler](https://github.com/ddengler), [David Kraus](https://github.com/davidkraus) and [Wolfgang Lutz](https://github.com/lutzifer).

0 commit comments

Comments
 (0)